bpo-42737: annotations with complex targets no longer causes any runtime effects (GH-23952)

This commit is contained in:
Batuhan Taskaya 2021-04-25 05:31:20 +03:00 committed by GitHub
parent 196983563d
commit 8cc3cfa8af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 0 deletions

View file

@ -134,8 +134,12 @@ class AnnotationsFutureTestCase(unittest.TestCase):
...
async def g2(arg: {ann}) -> None:
...
class H:
var: {ann}
object.attr: {ann}
var: {ann}
var2: {ann} = None
object.attr: {ann}
"""
)
@ -343,6 +347,13 @@ class AnnotationsFutureTestCase(unittest.TestCase):
self.assertAnnotationEqual("('inf', 1e1000, 'infxxx', 1e1000j)", expected=f"('inf', {inf}, 'infxxx', {infj})")
self.assertAnnotationEqual("(1e1000, (1e1000j,))", expected=f"({inf}, ({infj},))")
def test_annotation_with_complex_target(self):
with self.assertRaises(SyntaxError):
exec(
"from __future__ import annotations\n"
"object.__debug__: int"
)
if __name__ == "__main__":
unittest.main()