From f236e36729265602143ace2d969b44e53e4d57c1 Mon Sep 17 00:00:00 2001 From: Tim Martin Date: Fri, 30 Jul 2021 20:18:17 +0100 Subject: Infer the type of the result of calling typing.cast() (#1076) * Infer the type of the result of calling typing.cast() Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com> --- 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 31d190d2..dd040bd4 100644 --- a/tests/unittest_brain.py +++ b/tests/unittest_brain.py @@ -1810,6 +1810,38 @@ class TypingBrain(unittest.TestCase): self.assertIsInstance(inferred, nodes.ClassDef) self.assertIsInstance(inferred.getattr("__iter__")[0], nodes.FunctionDef) + def test_typing_cast(self): + node = builder.extract_node( + """ + from typing import cast + class A: + pass + + b = 42 + a = cast(A, b) + a + """ + ) + inferred = next(node.infer()) + assert isinstance(inferred, nodes.Const) + assert inferred.value == 42 + + def test_typing_cast_attribute(self): + node = builder.extract_node( + """ + import typing + class A: + pass + + b = 42 + a = typing.cast(A, b) + a + """ + ) + inferred = next(node.infer()) + assert isinstance(inferred, nodes.Const) + assert inferred.value == 42 + class ReBrainTest(unittest.TestCase): def test_regex_flags(self): -- cgit v1.2.1