Message359502
We might need to tweak the documentation @pablogsal,
> Unparse an ast.AST object and generate a string with code that would produce an equivalent ast.AST object if parsed back with ast.parse().
If I interpret `equivalent` correctly, this explanation is false under cases like constant nodes has an immutable container value (which they can).
>>> def wrap(expr):
... return ast.Module(body=[ast.Expr(expr)], type_ignores=[])
...
>>> constant_tuple = wrap(ast.Constant(value=(1, 2, 3), kind=None))
>>> normalpy_tuple = ast.parse("(1, 2, 3)")
>>> ast.unparse(constant_tuple) == ast.unparse(normalpy_tuple)
True
>>> ast.dump(ast.parse(ast.unparse(constant_tuple))) != ast.dump(constant_tuple)
True
>>> ast.dump(ast.parse(ast.unparse(constant_tuple))) == ast.dump(normalpy_tuple)
True
This isn't a bug in the code because there is no way we can generate a string that can produce a constant tuple. But this makes the docstring false, at least in certain cases. |
|
Date |
User |
Action |
Args |
2020-01-07 11:25:15 | BTaskaya | set | recipients:
+ BTaskaya, brett.cannon, vstinner, levkivskyi, pablogsal, miss-islington, brandtbucher, Batuhan Taskaya |
2020-01-07 11:25:15 | BTaskaya | set | messageid: <1578396315.01.0.12206591729.issue38870@roundup.psfhosted.org> |
2020-01-07 11:25:14 | BTaskaya | link | issue38870 messages |
2020-01-07 11:25:14 | BTaskaya | create | |
|