Files
micropython/tests/cpydiff/syntax_annotation_expression.py
Jeff Epler e29bcdcb7b tests/cpydiff: Add test file for annotation expressions.
Document the behavior on expression annotations rejected by CPython but
accepted by MicroPython.

Closes issue #19031.

Signed-off-by: Jeff Epler <jepler@unpythonic.net>
2026-04-07 14:45:09 +10:00

25 lines
600 B
Python

"""
categories: Syntax,Annotations
description: MicroPython accepts type annotations on expressions where CPython forbids them.
cause: To reduce code size, MicroPython does not check the form of expressions with type annotations applied.
workaround: Always check for valid Python code using a linting tool.
The expressions themselves are not evaluated.
"""
def test(expr):
code = f"def f():\n {expr}: int"
print(code)
try:
exec(code)
print("OK")
except SyntaxError as e:
print("SyntaxError")
print()
test("print('test')")
test("[x,y]")
test("x,y")