[issue38131] compile(mode='eval') uninformative error message

Batuhan report at bugs.python.org
Fri Dec 27 11:27:01 EST 2019


Batuhan <batuhanosmantaskaya at gmail.com> added the comment:

with PR 17715 

>>> import ast
>>> expr_without_lineno_but_ok = ast.Expression(body=ast.BinOp(left=ast.Num(n=2), right=ast.Num(n=2), op=ast.Add()))
>>> expr_with_lineno_but_with_wrong_body = ast.Expression(body=[ast.BinOp(left=ast.Num(n=2), right=ast.Num(n=2), op=ast.Add())])
>>> ast.fix_missing_locations(expr_with_lineno_but_with_wrong_body)
>>> compile(expr_without_lineno_but_ok, "<temp>", "eval")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: required field "lineno" missing from expr
>>> compile(expr_with_lineno_but_with_wrong_body, "<temp>", "eval")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: expected some sort of expr, but got [<_ast.BinOp object at 0x7f3f57dc4c80>]

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38131>
_______________________________________


More information about the Python-bugs-list mailing list