Skip to content
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

No universal newline support for compile() when using bytes #48878

Closed
brettcannon opened this issue Dec 11, 2008 · 4 comments
Closed

No universal newline support for compile() when using bytes #48878

brettcannon opened this issue Dec 11, 2008 · 4 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@brettcannon
Copy link
Member

BPO 4628
Nosy @brettcannon, @vstinner, @benjaminp

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 = None
closed_at = <Date 2009-11-12.23:40:16.739>
created_at = <Date 2008-12-11.06:54:06.688>
labels = ['interpreter-core', 'type-bug']
title = 'No universal newline support for compile() when using bytes'
updated_at = <Date 2009-11-12.23:40:16.733>
user = 'https://github.com/brettcannon'

bugs.python.org fields:

activity = <Date 2009-11-12.23:40:16.733>
actor = 'benjamin.peterson'
assignee = 'none'
closed = True
closed_date = <Date 2009-11-12.23:40:16.739>
closer = 'benjamin.peterson'
components = ['Interpreter Core']
creation = <Date 2008-12-11.06:54:06.688>
creator = 'brett.cannon'
dependencies = []
files = []
hgrepos = []
issue_num = 4628
keywords = []
message_count = 4.0
messages = ['77596', '83847', '84127', '95164']
nosy_count = 3.0
nosy_names = ['brett.cannon', 'vstinner', 'benjamin.peterson']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'needs patch'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue4628'
versions = ['Python 3.0']

@brettcannon
Copy link
Member Author

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

@brettcannon brettcannon added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Dec 11, 2008
@vstinner
Copy link
Member

This problem is not new. exec() in Python 2.x doesn't accept \r\n
newlines.

See also related(?) issue: bpo-5524

@vstinner
Copy link
Member

See also related issue: bpo-4377 (tokenize.detect_encoding() and Mac
newline).

@benjaminp
Copy link
Contributor

Finally got around to fixing this. r76230

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants