Skip to content

Commit 2f97d1d

Browse files
jeplerdpgeorge
authored andcommitted
tests/cpydiff: Document that uPy requires space after number+period.
Signed-off-by: Jeff Epler <jepler@gmail.com>
1 parent e22c666 commit 2f97d1d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tests/cpydiff/syntax_spaces.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""
22
categories: Syntax,Spaces
3-
description: MicroPython requires spaces between literal numbers and keywords, CPython doesn't
3+
description: MicroPython requires spaces between literal numbers and keywords or ".", CPython doesn't
44
cause: Different parser implementation
55
66
MicroPython's tokenizer treats a sequence like ``1and`` as a single token, while CPython treats it as two tokens.
77
8-
Since CPython 3.11, this syntax causes a ``SyntaxWarning`` for an "invalid literal".
8+
Since CPython 3.11, when the literal number is followed by a token, this syntax causes a ``SyntaxWarning`` for an "invalid literal". When a literal number is followed by a "." denoting attribute access, CPython does not warn.
99
1010
workaround: Add a space between the integer literal and the intended next token.
1111
@@ -24,3 +24,7 @@
2424
print(eval("1if 1else 0"))
2525
except SyntaxError:
2626
print("Should have worked")
27+
try:
28+
print(eval("0x1.to_bytes(1)"))
29+
except SyntaxError:
30+
print("Should have worked")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy