Message322084
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. |
|
Date |
User |
Action |
Args |
2018-07-21 08:12:18 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, gvanrossum, terry.reedy, kayhayen, Mark.Shannon, levkivskyi |
2018-07-21 08:12:18 | serhiy.storchaka | set | messageid: <1532160738.62.0.56676864532.issue34136@psf.upfronthosting.co.za> |
2018-07-21 08:12:18 | serhiy.storchaka | link | issue34136 messages |
2018-07-21 08:12:18 | serhiy.storchaka | create | |
|