[issue34136] Del on class __annotations__ regressed, failing test
Serhiy Storchaka
report at bugs.python.org
Sat Jul 21 04:12:18 EDT 2018
Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:
In the edition of PR 8364 the test is failed on 3.6.
def test_do_not_recreate_annotations(self):
annotations = {}
# Don't rely on the existence of the '__annotations__' global.
with support.swap_item(globals(), '__annotations__', annotations):
class C:
del __annotations__
x: int # Updates the '__annotations__' global.
self.assertIn('x', annotations)
self.assertIs(annotations['x'], int)
It is possible to write it in less strong form which will be passed on 3.6 too.
def test_do_not_recreate_annotations(self):
# Don't rely on the existence of the '__annotations__' global.
with support.swap_item(globals(), '__annotations__', {}):
del globals()['__annotations__']
class C:
del __annotations__
with self.assertRaises(NameError):
x: int
In 3.6 the annotation declaration fails immediately if __annotations__ is deleted. In 3.7 it falls back to the global __annotations__.
The question is whether the difference in the behavior between 3.6 and 3.7 is intended and is a part of the language specification, or is an implementation detail of CPython. In the former case we can keep the stronger test. In the latter case we should make it weaker.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34136>
_______________________________________
More information about the Python-bugs-list
mailing list