mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-43901: Lazy-create an empty annotations dict in all unannotated user classes and modules (#25623)
Change class and module objects to lazy-create empty annotations dicts on demand. The annotations dicts are stored in the object's `__dict__` for backwards compatibility.
This commit is contained in:
parent
dbe60ee09d
commit
2f2b69855d
9 changed files with 308 additions and 8 deletions
|
@ -382,8 +382,7 @@ class GrammarTests(unittest.TestCase):
|
|||
self.assertEqual(CC.__annotations__['xx'], 'ANNOT')
|
||||
|
||||
def test_var_annot_module_semantics(self):
|
||||
with self.assertRaises(AttributeError):
|
||||
print(test.__annotations__)
|
||||
self.assertEqual(test.__annotations__, {})
|
||||
self.assertEqual(ann_module.__annotations__,
|
||||
{1: 2, 'x': int, 'y': str, 'f': typing.Tuple[int, int]})
|
||||
self.assertEqual(ann_module.M.__annotations__,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue