10000 unyielding · python/cpython@8c4b4e3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8c4b4e3

Browse files
committed
unyielding
1 parent f452eb2 commit 8c4b4e3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Lib/test/test_type_annotations.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import textwrap
22
import types
33
import unittest
4-
from test.support import run_code
4+
from test.support import run_code, check_syntax_error
55

66

77
class TypeAnnotationTests(unittest.TestCase):
@@ -327,3 +327,9 @@ class Nested: ...
327327

328328
self.assertEqual(Outer.meth.__annotations__, {"x": Outer.Nested})
329329
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")

0 commit comments

Comments
 (0)
0