File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change 1
1
import textwrap
2
2
import types
3
3
import unittest
4
- from test .support import run_code
4
+ from test .support import run_code , check_syntax_error
5
5
6
6
7
7
class TypeAnnotationTests (unittest .TestCase ):
@@ -327,3 +327,9 @@ class Nested: ...
327
327
328
328
self .assertEqual (Outer .meth .__annotations__ , {"x" : Outer .Nested })
329
329
self .assertEqual (Outer .__annotations__ , {"x" : Outer .Nested })
330
+
331
+ def test_no_exotic_expressions (self ):
332
+ check_syntax_error (self , "def func(x: (yield)): ..." , "yield expression cannot be used within an annotation" )
333
+ check_syntax_error (self , "def func(x: (yield from x)): ..." , "yield expression cannot be used within an annotation" )
334
+ check_syntax_error (self , "def func(x: (y := 3)): ..." , "named expression cannot be used within an annotation" )
335
+ check_syntax_error (self , "def func(x: (await 42)): ..." , "await expression cannot be used within an annotation" )
You can’t perform that action at this time.
0 commit comments