Skip to content

Commit e29bcdc

Browse files
jeplerdpgeorge
authored andcommitted
tests/cpydiff: Add test file for annotation expressions.
Document the behavior on expression annotations rejected by CPython but accepted by MicroPython. Closes issue micropython#19031. Signed-off-by: Jeff Epler <jepler@unpythonic.net>
1 parent c3b3f20 commit e29bcdc

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
categories: Syntax,Annotations
3+
description: MicroPython accepts type annotations on expressions where CPython forbids them.
4+
cause: To reduce code size, MicroPython does not check the form of expressions with type annotations applied.
5+
workaround: Always check for valid Python code using a linting tool.
6+
7+
The expressions themselves are not evaluated.
8+
"""
9+
10+
11+
def test(expr):
12+
code = f"def f():\n {expr}: int"
13+
print(code)
14+
try:
15+
exec(code)
16+
print("OK")
17+
except SyntaxError as e:
18+
print("SyntaxError")
19+
print()
20+
21+
22+
test("print('test')")
23+
test("[x,y]")
24+
test("x,y")

0 commit comments

Comments
 (0)