You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
No universal newline support for compile() when using bytes #48878
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2009-11-12.23:40:16.739>created_at=<Date2008-12-11.06:54:06.688>labels= ['interpreter-core', 'type-bug']
title='No universal newline support for compile() when using bytes'updated_at=<Date2009-11-12.23:40:16.733>user='https://github.com/brettcannon'
Passing in bytes to compile() works well for letting the parser handle
the decoding of a file when an encoding is specified, but it doesn't
take care of universal newlines::
>>> source = b'a = 1\r\nb = 2\r\n'
>>> compile(source, '<test>', 'exec')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<test>", line 1
a = 1
^
SyntaxError: invalid syntax
Activity
brettcannon commentedon Dec 11, 2008
Passing in bytes to compile() works well for letting the parser handle
the decoding of a file when an encoding is specified, but it doesn't
take care of universal newlines::
>>> source = b'a = 1\r\nb = 2\r\n' >>> compile(source, '<test>', 'exec') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<test>", line 1 a = 1 ^ SyntaxError: invalid syntaxvstinner commentedon Mar 20, 2009
This problem is not new. exec() in Python 2.x doesn't accept \r\n
newlines.
See also related(?) issue: bpo-5524
vstinner commentedon Mar 24, 2009
See also related issue: bpo-4377 (tokenize.detect_encoding() and Mac
newline).
benjaminp commentedon Nov 12, 2009
Finally got around to fixing this. r76230