Skip to content

cpython difference parsing "invalid" literals #17224

Closed
@jepler

Description

@jepler

Port, board and/or hardware

unix

MicroPython version

MicroPython v1.26.0-preview.24.gcd8fad919f.dirty on 2025-04-22; linux [GCC 12.2.0] version

Reproduction

  1. micropython -c 'print(0x1or 2)
  2. python3.9 -c 'print(0x1or 2)

Expected behaviour

Both implementations print the same value

Observed behaviour

micropython raises an exception, while python prints "1" (Python versions starting with 3.11 print a warning though)

Additional Information

The warning about this syntax appeared in Python 3.11 as a result of https://bugs.python.org/issue43833. There appears to be no intent to actually convert this to a SyntaxError, though only for the risk of breaking existing code, not because anyone likes the construct.

Sorry for not filing this bug on April 1. Some post on mastodon alerted me to the fact that 0x1for....real is valid Python and I just had to check it out on micropython.

Code of Conduct

Yes, I agree

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpy-coreRelates to py/ directory in source

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions