Lib/_ast_unparse.py's visit_Attribute inserts a space before the "."
when node.value is an int literal, to avoid the syntax error in
3.abs(). But bool is a subclass of int, so True.real and
False.class also get the space:
>>> import ast
>>> ast.unparse(ast.parse("x = True.real"))
'x = True .real'
>>> ast.unparse(ast.parse("x = False.__class__"))
'x = False .__class__'
True.real and False.class are valid without a space, so the
output is not idiomatic. The fix is to exclude bool from the
isinstance check:
if (isinstance(node.value, Constant)
and isinstance(node.value.value, int)
and not isinstance(node.value.value, bool)):
self.write(" ")
I'd like to submit a PR with this fix and a test.
Linked PRs
Lib/_ast_unparse.py's visit_Attribute inserts a space before the "."
when node.value is an int literal, to avoid the syntax error in
3.abs(). But bool is a subclass of int, so True.real and
False.class also get the space:
True.real and False.class are valid without a space, so the
output is not idiomatic. The fix is to exclude bool from the
isinstance check:
I'd like to submit a PR with this fix and a test.
Linked PRs