Batuhan <batuhanosmantask...@gmail.com> added the comment:
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. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue38870> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com