-
-
Notifications
You must be signed in to change notification settings - Fork 31.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regression in tokenizer handling of \r
#128233
Comments
There's one more interesting one, when the tokenizer seems to think that $ printf 'foo\n\r \nbar' | python3.11 -m tokenize
1,0-1,3: NAME 'foo'
1,3-1,4: NEWLINE '\n'
2,0-2,3: NL '\r \n'
3,0-3,3: NAME 'bar'
3,3-3,4: NEWLINE ''
4,0-4,0: ENDMARKER ''
$ printf 'foo\n\r \nbar' | python3.12 -m tokenize
1,0-1,3: NAME 'foo'
1,3-1,4: NEWLINE '\n'
2,0-2,2: OP '\r '
2,2-2,3: NEWLINE '\n'
3,0-3,3: NAME 'bar'
3,3-3,4: NEWLINE ''
4,0-4,0: ENDMARKER '' I would have expected the |
The behavior was changed because the |
Another weird case, where we also get a $ python -m tokenize x.py
0,0-0,0: ENCODING 'utf-8'
1,0-1,1: NL '\n'
2,0-2,1: COMMENT '#'
2,1-2,3: NUMBER '\r0'
2,3-2,4: NL ''
3,0-3,0: ENDMARKER ''
$ python3.11 -m tokenize x.py
0,0-0,0: ENCODING 'utf-8'
1,0-1,1: NL '\n'
2,0-2,3: COMMENT '#\r0'
2,3-2,3: NL ''
3,0-3,0: ENDMARKER '' |
Bug report
Bug description:
Python 3.12 onwards we get a weird
\r}
token when trying to parse a file just containing'{\r}'
:Weirdly, AST generation passes just fine in both cases:
Expected behaviour
I'd expect the
\r
to yield aNL
instead, and we get a}
OP
as expected.CPython versions tested on:
3.11, 3.12, 3.13, 3.14
Operating systems tested on:
macOS
The text was updated successfully, but these errors were encountered: