.. This document was generated by tools/gen-cpydiff.py Syntax ====== Generated Wed 03 Jan 2024 12:07:50 UTC Operators --------- .. _cpydiff_syntax_assign_expr: MicroPython allows using := to assign to the variable of a comprehension, CPython raises a SyntaxError. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ **Cause:** MicroPython is optimised for code size and doesn't check this case. **Workaround:** Do not rely on this behaviour if writing CPython compatible code. Sample code:: print([i := -1 for i in range(4)]) +-------------------------------------------------------------------------------------------+-------------------------------------------------------------------+ | CPy output: | uPy output: | +-------------------------------------------------------------------------------------------+-------------------------------------------------------------------+ | :: | :: | | | | | File "", line 7 | /bin/sh: ../ports/unix/micropython: No such file or directory | | SyntaxError: assignment expression cannot rebind comprehension iteration variable 'i' | | +-------------------------------------------------------------------------------------------+-------------------------------------------------------------------+ Spaces ------ .. _cpydiff_syntax_spaces: uPy requires spaces between literal numbers and keywords, CPy doesn't ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Sample code:: try: print(eval("1and 0")) except SyntaxError: print("Should have worked") try: print(eval("1or 0")) except SyntaxError: print("Should have worked") try: print(eval("1if 1else 0")) except SyntaxError: print("Should have worked") +-------------+-------------------------------------------------------------------+ | CPy output: | uPy output: | +-------------+-------------------------------------------------------------------+ | :: | :: | | | | | 0 | /bin/sh: ../ports/unix/micropython: No such file or directory | | 1 | | | 1 | | +-------------+-------------------------------------------------------------------+ Unicode ------- .. _cpydiff_syntax_unicode_nameesc: Unicode name escapes are not implemented ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Sample code:: print("\N{LATIN SMALL LETTER A}") +-------------+-------------------------------------------------------------------+ | CPy output: | uPy output: | +-------------+-------------------------------------------------------------------+ | :: | :: | | | | | a | /bin/sh: ../ports/unix/micropython: No such file or directory | +-------------+-------------------------------------------------------------------+