Message80559
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). |
|
Date |
User |
Action |
Args |
2009-01-26 03:25:44 | exarkun | set | recipients:
+ exarkun |
2009-01-26 03:25:44 | exarkun | set | messageid: <1232940344.37.0.615917855536.issue5064@psf.upfronthosting.co.za> |
2009-01-26 03:25:43 | exarkun | link | issue5064 messages |
2009-01-26 03:25:42 | exarkun | create | |
|