Author serhiy.storchaka
Recipients Mark.Shannon, gvanrossum, kayhayen, levkivskyi, serhiy.storchaka, terry.reedy
Date 2018-07-21.08:12:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1532160738.62.0.56676864532.issue34136@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-07-21 08:12:18serhiy.storchakasetrecipients: + serhiy.storchaka, gvanrossum, terry.reedy, kayhayen, Mark.Shannon, levkivskyi
2018-07-21 08:12:18serhiy.storchakasetmessageid: <1532160738.62.0.56676864532.issue34136@psf.upfronthosting.co.za>
2018-07-21 08:12:18serhiy.storchakalinkissue34136 messages
2018-07-21 08:12:18serhiy.storchakacreate