mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
gh-133037: Add test for shadowing __annotate__ (#133084)
This commit is contained in:
parent
245cd6c532
commit
345fdce1d0
1 changed files with 19 additions and 0 deletions
|
@ -327,6 +327,25 @@ class AnnotateTests(unittest.TestCase):
|
||||||
f.__annotations__ = {"z": 43}
|
f.__annotations__ = {"z": 43}
|
||||||
self.assertIs(f.__annotate__, None)
|
self.assertIs(f.__annotate__, None)
|
||||||
|
|
||||||
|
def test_user_defined_annotate(self):
|
||||||
|
class X:
|
||||||
|
a: int
|
||||||
|
|
||||||
|
def __annotate__(format):
|
||||||
|
return {"a": str}
|
||||||
|
self.assertEqual(X.__annotate__(annotationlib.Format.VALUE), {"a": str})
|
||||||
|
self.assertEqual(annotationlib.get_annotations(X), {"a": str})
|
||||||
|
|
||||||
|
mod = build_module(
|
||||||
|
"""
|
||||||
|
a: int
|
||||||
|
def __annotate__(format):
|
||||||
|
return {"a": str}
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
self.assertEqual(mod.__annotate__(annotationlib.Format.VALUE), {"a": str})
|
||||||
|
self.assertEqual(annotationlib.get_annotations(mod), {"a": str})
|
||||||
|
|
||||||
|
|
||||||
class DeferredEvaluationTests(unittest.TestCase):
|
class DeferredEvaluationTests(unittest.TestCase):
|
||||||
def test_function(self):
|
def test_function(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue