This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: compiler.parse raises SyntaxErrors without line number information
Type: behavior Stage: needs patch
Components: Library (Lib) Versions:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: nascheme Nosy List: benjamin.peterson, exarkun, georg.brandl, nascheme
Priority: low Keywords:

Created on 2009-01-26 03:25 by exarkun, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg80559 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2009-01-26 03:25
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).
msg80561 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-01-26 03:51
Patches are welcome! The compiler package is deprecated in favor of
builtin AST.
msg88161 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2009-05-21 16:07
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.
msg92238 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-09-04 07:56
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".
History
Date User Action Args
2022-04-11 14:56:44adminsetgithub: 49314
2009-09-04 07:56:42georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg92238

resolution: wont fix
2009-05-21 16:07:46exarkunsetmessages: + msg88161
2009-02-07 01:01:08naschemesetassignee: nascheme
nosy: + nascheme
2009-01-26 03:51:37benjamin.petersonsetpriority: low
nosy: + benjamin.peterson
messages: + msg80561
stage: needs patch
2009-01-26 03:25:43exarkuncreate