Serhiy Storchaka <storchaka+cpyt...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue34136>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to