summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_inspect.py
diff options
context:
space:
mode:
authorBatuhan Taskaya <isidentical@gmail.com>2020-12-23 22:45:13 (GMT)
committerGitHub <noreply@github.com>2020-12-23 22:45:13 (GMT)
commiteee1c7745ab4eb4f75153e71aaa2a62018b7625a (patch)
tree53ba864b0213e139d3b4f03ca8815bab24448740 /Lib/test/test_inspect.py
parent6b1ac809b9718a369aea67b99077cdd682be2238 (diff)
downloadcpython-eee1c7745ab4eb4f75153e71aaa2a62018b7625a.zip
cpython-eee1c7745ab4eb4f75153e71aaa2a62018b7625a.tar.gz
cpython-eee1c7745ab4eb4f75153e71aaa2a62018b7625a.tar.bz2
bpo-41960: Add globalns and localns parameters to inspect.signature and Signature.from_callable (GH-22583)
Diffstat (limited to 'Lib/test/test_inspect.py')
-rw-r--r--Lib/test/test_inspect.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index c81d828..706fcbe 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -3250,6 +3250,26 @@ class TestSignatureObject(unittest.TestCase):
p2 = inspect.signature(lambda y, x: None).parameters
self.assertNotEqual(p1, p2)
+ def test_signature_annotations_with_local_namespaces(self):
+ class Foo: ...
+ def func(foo: Foo) -> int: pass
+ def func2(foo: Foo, bar: Bar) -> int: pass
+
+ for signature_func in (inspect.signature, inspect.Signature.from_callable):
+ with self.subTest(signature_func = signature_func):
+ sig1 = signature_func(func)
+ self.assertEqual(sig1.return_annotation, 'int')
+ self.assertEqual(sig1.parameters['foo'].annotation, 'Foo')
+
+ sig2 = signature_func(func, localns=locals())
+ self.assertEqual(sig2.return_annotation, int)
+ self.assertEqual(sig2.parameters['foo'].annotation, Foo)
+
+ sig3 = signature_func(func2, globalns={'Bar': int}, localns=locals())
+ self.assertEqual(sig3.return_annotation, int)
+ self.assertEqual(sig3.parameters['foo'].annotation, Foo)
+ self.assertEqual(sig3.parameters['bar'].annotation, int)
+
class TestParameterObject(unittest.TestCase):
def test_signature_parameter_kinds(self):