mirror of
https://github.com/python/cpython.git
synced 2025-10-21 14:12:27 +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
|
@ -31,10 +31,9 @@ class OpcodeTest(unittest.TestCase):
|
|||
except OSError:
|
||||
pass
|
||||
|
||||
def test_no_annotations_if_not_needed(self):
|
||||
def test_default_annotations_exist(self):
|
||||
class C: pass
|
||||
with self.assertRaises(AttributeError):
|
||||
C.__annotations__
|
||||
self.assertEqual(C.__annotations__, {})
|
||||
|
||||
def test_use_existing_annotations(self):
|
||||
ns = {'__annotations__': {1: 2}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue