From 0c9ab0fe56703fa83c73e514a1020d398d23fa7f Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sun, 22 Jan 2023 15:31:44 +0100 Subject: Fix issues with `typing_extensions.TypeVar` (#1973) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com> Co-authored-by: Pierre Sassoulas --- tests/unittest_brain.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests') 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()] -- cgit v1.2.1