summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_future.py
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2020-03-18 23:02:09 (GMT)
committerGitHub <noreply@github.com>2020-03-18 23:02:09 (GMT)
commitd112c600ab3f5e2910345bcc4bfc39439917ed87 (patch)
tree1b260548a6f6b9bebcbf9be74bcfb3f3f8a39068 /Lib/test/test_future.py
parent8849e5962ba481d5d414b3467a256aba2134b4da (diff)
downloadcpython-d112c600ab3f5e2910345bcc4bfc39439917ed87.zip
cpython-d112c600ab3f5e2910345bcc4bfc39439917ed87.tar.gz
cpython-d112c600ab3f5e2910345bcc4bfc39439917ed87.tar.bz2
bpo-39220: Do not optimise annotation if 'from __future__ import annotations' is used (GH-17866)
Do not apply AST-based optimizations if 'from __future__ import annotations' is used in order to prevent information lost in the final version of the annotations.
Diffstat (limited to 'Lib/test/test_future.py')
-rw-r--r--Lib/test/test_future.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/test/test_future.py b/Lib/test/test_future.py
index d83c47e..9b88e3f 100644
--- a/Lib/test/test_future.py
+++ b/Lib/test/test_future.py
@@ -111,6 +111,10 @@ class AnnotationsFutureTestCase(unittest.TestCase):
...
def g(arg: {ann}) -> None:
...
+ async def f2() -> {ann}:
+ ...
+ async def g2(arg: {ann}) -> None:
+ ...
var: {ann}
var2: {ann} = None
"""
@@ -121,9 +125,13 @@ class AnnotationsFutureTestCase(unittest.TestCase):
exec(self.template.format(ann=annotation), {}, scope)
func_ret_ann = scope['f'].__annotations__['return']
func_arg_ann = scope['g'].__annotations__['arg']
+ async_func_ret_ann = scope['f2'].__annotations__['return']
+ async_func_arg_ann = scope['g2'].__annotations__['arg']
var_ann1 = scope['__annotations__']['var']
var_ann2 = scope['__annotations__']['var2']
self.assertEqual(func_ret_ann, func_arg_ann)
+ self.assertEqual(func_ret_ann, async_func_ret_ann)
+ self.assertEqual(func_ret_ann, async_func_arg_ann)
self.assertEqual(func_ret_ann, var_ann1)
self.assertEqual(func_ret_ann, var_ann2)
return func_ret_ann
@@ -288,6 +296,7 @@ class AnnotationsFutureTestCase(unittest.TestCase):
eq('(((a, b)))', '(a, b)')
eq("(x:=10)")
eq("f'{(x:=10):=10}'")
+ eq("1 + 2 + 3")
def test_fstring_debug_annotations(self):
# f-strings with '=' don't round trip very well, so set the expected
@@ -299,6 +308,5 @@ class AnnotationsFutureTestCase(unittest.TestCase):
self.assertAnnotationEqual("f'{x=!a}'", expected="f'x={x!a}'")
self.assertAnnotationEqual("f'{x=!s:*^20}'", expected="f'x={x!s:*^20}'")
-
if __name__ == "__main__":
unittest.main()