summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTim Martin <tim@asymptotic.co.uk>2021-07-30 20:18:17 +0100
committerGitHub <noreply@github.com>2021-07-30 21:18:17 +0200
commitf236e36729265602143ace2d969b44e53e4d57c1 (patch)
treec634d68f7e5bd1e4fb5c21cbef0362ac54751f51 /tests
parente7f4def327e749f2f2db3bf3412b9dc4e22359ef (diff)
downloadastroid-git-f236e36729265602143ace2d969b44e53e4d57c1.tar.gz
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>
Diffstat (limited to 'tests')
-rw-r--r--tests/unittest_brain.py32
1 files changed, 32 insertions, 0 deletions
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):