Skip to content

[pycodestyle] Don't treat None, True, or False as keywords (E271-E274) - #29322

Merged
ntBre merged 2 commits into
astral-sh:mainfrom
fixfon:fix-e272-singletons
Oct 13, 2026
Merged

ntBre merged 2 commits into
astral-sh:mainfrom
fixfon:fix-e272-singletons

Conversation

@fixfon

@fixfon fixfon commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

pycodestyle excludes None, True and False from its keyword list (KEYWORDS = kwlist - SINGLETONS), but ruff was still flagging whitespace around them in E271-E274. E275 already handles this correctly, so I just added the same !is_singleton() check in whitespace_around_keywords.rs.

The example from the issue used to give E272, now it passes. Two existing fixture cases (True and False and True\t\tand\tFalse) now report what pycodestyle reports, so I moved them under their own #: headers and added a few new cases to E27.py.

cargo test -p ruff_linter passes and clippy is clean.

E225/E226 seem to have the same mismatch. I left that out to keep this small, happy to open a separate issue.

I used an AI assistant while working on this. I went through the change myself and checked it against pycodestyle.

Fixes #29215

@astral-sh-bot

astral-sh-bot Bot commented Oct 13, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+1 -16 violations, +0 -0 fixes in 3 projects; 55 projects unchanged)

DisnakeDev/disnake (+0 -15 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

- disnake/enums.py:751:33: multiple-spaces-before-keyword [*] Multiple spaces before keyword
- disnake/enums.py:752:41: multiple-spaces-before-keyword [*] Multiple spaces before keyword
- disnake/enums.py:753:32: multiple-spaces-before-keyword [*] Multiple spaces before keyword
- disnake/enums.py:754:34: multiple-spaces-before-keyword [*] Multiple spaces before keyword
- disnake/enums.py:757:40: multiple-spaces-before-keyword [*] Multiple spaces before keyword
- disnake/enums.py:758:46: multiple-spaces-before-keyword [*] Multiple spaces before keyword
- disnake/enums.py:759:36: multiple-spaces-before-keyword [*] Multiple spaces before keyword
- disnake/enums.py:774:40: multiple-spaces-before-keyword [*] Multiple spaces before keyword
- disnake/enums.py:775:42: multiple-spaces-before-keyword [*] Multiple spaces before keyword
- disnake/enums.py:798:50: multiple-spaces-before-keyword [*] Multiple spaces before keyword
- disnake/enums.py:799:55: multiple-spaces-before-keyword [*] Multiple spaces before keyword
- disnake/enums.py:800:44: multiple-spaces-before-keyword [*] Multiple spaces before keyword
- disnake/enums.py:801:52: multiple-spaces-before-keyword [*] Multiple spaces before keyword
- disnake/enums.py:802:65: multiple-spaces-before-keyword [*] Multiple spaces before keyword
- disnake/enums.py:803:64: multiple-spaces-before-keyword [*] Multiple spaces before keyword

bokeh/bokeh (+0 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview --select ALL

- examples/server/app/surface3d/surface3d.py:13:16: multiple-spaces-before-keyword [*] Multiple spaces before keyword

indico/indico (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

+ indico/modules/rb/models/reservations.py:53:87: RUF100 [*] Unused `noqa` directive (unused: `E272`)

Changes by rule (2 rules affected)

code total + violation - violation + fix - fix
multiple-spaces-before-keyword 16 0 16 0 0
RUF100 1 1 0 0 0

@ntBre ntBre added rule Implementing or modifying a lint rule preview Related to preview-mode features labels Oct 13, 2026

@ntBre ntBre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ntBre ntBre changed the title [pycodestyle] Don't treat None, True and False as keywords in E271-E274 [pycodestyle] Don't treat None, True, or False as keywords (E271-E274) Oct 13, 2026
@ntBre
ntBre enabled auto-merge (squash) October 13, 2026 14:14
@ntBre
ntBre merged commit 076f892 into astral-sh:main Oct 13, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview Related to preview-mode features rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

E272 incorrectly treats None, True and False as keywords

2 participants