|
66 | 66 | except ImportError:
|
67 | 67 | HAS_SIX = False
|
68 | 68 |
|
| 69 | +try: |
| 70 | + import typing_extensions # pylint: disable=unused-import |
| 71 | + |
| 72 | + HAS_TYPING_EXTENSIONS = True |
| 73 | + HAS_TYPING_EXTENSIONS_TYPEVAR = hasattr(typing_extensions, "TypeVar") |
| 74 | +except ImportError: |
| 75 | + HAS_TYPING_EXTENSIONS = False |
| 76 | + HAS_TYPING_EXTENSIONS_TYPEVAR = False |
| 77 | + |
69 | 78 |
|
70 | 79 | def assertEqualMro(klass: ClassDef, expected_mro: list[str]) -> None:
|
71 | 80 | """Check mro names."""
|
@@ -2148,6 +2157,29 @@ class A:
|
2148 | 2157 | assert inferred.value == 42
|
2149 | 2158 |
|
2150 | 2159 |
|
| 2160 | +@pytest.mark.skipif( |
| 2161 | + not HAS_TYPING_EXTENSIONS, |
| 2162 | + reason="These tests require the typing_extensions library", |
| 2163 | +) |
| 2164 | +class TestTypingExtensions: |
| 2165 | + @staticmethod |
| 2166 | + @pytest.mark.skipif( |
| 2167 | + not HAS_TYPING_EXTENSIONS_TYPEVAR, |
| 2168 | + reason="Need typing_extensions>=4.4.0 to test TypeVar", |
| 2169 | + ) |
| 2170 | + def test_typing_extensions_types() -> None: |
| 2171 | + ast_nodes = builder.extract_node( |
| 2172 | + """ |
| 2173 | + from typing_extensions import TypeVar |
| 2174 | + TypeVar('MyTypeVar', int, float, complex) #@ |
| 2175 | + TypeVar('AnyStr', str, bytes) #@ |
| 2176 | + """ |
| 2177 | + ) |
| 2178 | + for node in ast_nodes: |
| 2179 | + inferred = next(node.infer()) |
| 2180 | + assert isinstance(inferred, nodes.ClassDef) |
| 2181 | + |
| 2182 | + |
2151 | 2183 | class ReBrainTest(unittest.TestCase):
|
2152 | 2184 | def test_regex_flags(self) -> None:
|
2153 | 2185 | names = [name for name in dir(re) if name.isupper()]
|
|
0 commit comments