Skip to content

gh-158237: Don't insert space before attribute access on bool constants - #158238

Merged
JelleZijlstra merged 1 commit into
python:mainfrom
Tony123-tech:gh-158237-fix-unparse-bool-attribute
Sep 26, 2026
Merged

JelleZijlstra merged 1 commit into
python:mainfrom
Tony123-tech:gh-158237-fix-unparse-bool-attribute

Conversation

@Tony123-tech

@Tony123-tech Tony123-tech commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

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 excludes bool from the isinstance
check.

@bedevere-app

bedevere-app Bot commented Sep 26, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@Tony123-tech
Tony123-tech force-pushed the gh-158237-fix-unparse-bool-attribute branch from 05dd309 to aca1577 Compare September 26, 2026 14:07
@Tony123-tech
Tony123-tech force-pushed the gh-158237-fix-unparse-bool-attribute branch from aca1577 to edad754 Compare September 26, 2026 14:09
@JelleZijlstra
JelleZijlstra merged commit 9def455 into python:main Sep 26, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants