From 5901b8d149d63d74354bfb3f7f44a0b942eda23e Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 10 Jun 2025 08:21:14 +0200 Subject: [PATCH] tests/cpydiff: Document complex() parsing difference. In #17384 it was decided that fixing this difference was not worth the code size increase. So document it instead. Signed-off-by: Jeff Epler --- tests/cpydiff/types_complex_parser.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/cpydiff/types_complex_parser.py diff --git a/tests/cpydiff/types_complex_parser.py b/tests/cpydiff/types_complex_parser.py new file mode 100644 index 000000000..4a012987d --- /dev/null +++ b/tests/cpydiff/types_complex_parser.py @@ -0,0 +1,14 @@ +""" +categories: Types,complex +description: MicroPython's complex() accepts certain incorrect values that CPython rejects +cause: MicroPython is highly optimized for memory usage. +workaround: Do not use non-standard complex literals as argument to complex() + +MicroPython's ``complex()`` function accepts literals that contain a space and +no sign between the real and imaginary parts, and interprets it as a plus. +""" + +try: + print(complex("1 1j")) +except ValueError: + print("ValueError")