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

compiler.parse raises SyntaxErrors without line number information #49314

Closed
exarkun mannequin opened this issue Jan 26, 2009 · 4 comments
Closed

compiler.parse raises SyntaxErrors without line number information #49314

exarkun mannequin opened this issue Jan 26, 2009 · 4 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@exarkun
Copy link
Mannequin

exarkun mannequin commented Jan 26, 2009

BPO 5064
Nosy @nascheme, @birkenfeld, @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 = 'https://github.com/nascheme'
closed_at = <Date 2009-09-04.07:56:42.449>
created_at = <Date 2009-01-26.03:25:43.435>
labels = ['type-bug', 'library']
title = 'compiler.parse raises SyntaxErrors without line number information'
updated_at = <Date 2009-09-04.07:56:42.447>
user = 'https://bugs.python.org/exarkun'

bugs.python.org fields:

activity = <Date 2009-09-04.07:56:42.447>
actor = 'georg.brandl'
assignee = 'nascheme'
closed = True
closed_date = <Date 2009-09-04.07:56:42.449>
closer = 'georg.brandl'
components = ['Library (Lib)']
creation = <Date 2009-01-26.03:25:43.435>
creator = 'exarkun'
dependencies = []
files = []
hgrepos = []
issue_num = 5064
keywords = []
message_count = 4.0
messages = ['80559', '80561', '88161', '92238']
nosy_count = 4.0
nosy_names = ['nascheme', 'georg.brandl', 'exarkun', 'benjamin.peterson']
pr_nums = []
priority = 'low'
resolution = 'wont fix'
stage = 'needs patch'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue5064'
versions = []

@exarkun
Copy link
Mannequin Author

exarkun mannequin commented Jan 26, 2009

Sometimes a syntax error in source passed to compiler.parse´ causes a SyntaxError´ with lots of nice information to be raised:

>>> from compiler import parse
>>> try:
...     parse("def f(")
... except SyntaxError, e:
...     pass
...
>>> e
SyntaxError('unexpected EOF while parsing', (None, 1, 6, 'def f('))

But for other syntax errors, only a string message is provided, no
location information:

>>> try:
...     parse("def f(x=10, y): pass")
... except SyntaxError, f:
...     pass
...
>>> f
SyntaxError('non-default argument follows default argument',)
>>> try:
...     parse("f(x=10, y)")
... except SyntaxError, g:
...     pass
...
>>> g
SyntaxError('non-keyword arg after keyword arg',)
>>> 

On the other hand, the built in compiler produces exceptions which do
have this information in these cases.

The absence of the information makes the job of tools trying to operate
on Python source code more difficult (naively written, they'll simply
fail when they encounter one of these less informative exceptions).

@exarkun exarkun mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jan 26, 2009
@benjaminp
Copy link
Contributor

Patches are welcome! The compiler package is deprecated in favor of
builtin AST.

@nascheme nascheme self-assigned this Feb 7, 2009
@exarkun
Copy link
Mannequin Author

exarkun mannequin commented May 21, 2009

It seems a patch would be an enormous undertaking, as the data structure
returned by the parser does not include this information, and the parser
is written in C.

I'll just hack around this somehow. Don't expect a patch from me.

@birkenfeld
Copy link
Member

In light of

The compiler package is deprecated in favor of builtin AST.

and

It seems a patch would be an enormous undertaking,

I guess it's best to close this as "won't fix".

@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
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants