diff options
| author | Marc Mueller <30130371+cdce8p@users.noreply.github.com> | 2023-01-22 15:31:44 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-22 14:31:44 +0000 |
| commit | 0c9ab0fe56703fa83c73e514a1020d398d23fa7f (patch) | |
| tree | 436474ab304e2370b5644ba16f7c6d3e6f091170 /tests | |
| parent | c2519e52594fd5b971a0a1bf5094ec2fa307a7dd (diff) | |
| download | astroid-git-0c9ab0fe56703fa83c73e514a1020d398d23fa7f.tar.gz | |
Fix issues with `typing_extensions.TypeVar` (#1973)
Co-authored-by: Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/unittest_brain.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/unittest_brain.py b/tests/unittest_brain.py index 9ee0f98f..3374556b 100644 --- a/tests/unittest_brain.py +++ b/tests/unittest_brain.py @@ -66,6 +66,15 @@ try: except ImportError: HAS_SIX = False +try: + import typing_extensions # pylint: disable=unused-import + + HAS_TYPING_EXTENSIONS = True + HAS_TYPING_EXTENSIONS_TYPEVAR = hasattr(typing_extensions, "TypeVar") +except ImportError: + HAS_TYPING_EXTENSIONS = False + HAS_TYPING_EXTENSIONS_TYPEVAR = False + def assertEqualMro(klass: ClassDef, expected_mro: list[str]) -> None: """Check mro names.""" @@ -2148,6 +2157,29 @@ class TypingBrain(unittest.TestCase): assert inferred.value == 42 +@pytest.mark.skipif( + not HAS_TYPING_EXTENSIONS, + reason="These tests require the typing_extensions library", +) +class TestTypingExtensions: + @staticmethod + @pytest.mark.skipif( + not HAS_TYPING_EXTENSIONS_TYPEVAR, + reason="Need typing_extensions>=4.4.0 to test TypeVar", + ) + def test_typing_extensions_types() -> None: + ast_nodes = builder.extract_node( + """ + from typing_extensions import TypeVar + TypeVar('MyTypeVar', int, float, complex) #@ + TypeVar('AnyStr', str, bytes) #@ + """ + ) + for node in ast_nodes: + inferred = next(node.infer()) + assert isinstance(inferred, nodes.ClassDef) + + class ReBrainTest(unittest.TestCase): def test_regex_flags(self) -> None: names = [name for name in dir(re) if name.isupper()] |
