Repository navigation
[syntax-errors] Extend __debug__ write check to attribute targets - #27908
Merged
Merged
Conversation
Memory usage reportMemory usage unchanged β |
|
Sacrimento
commented
Aug 19, 2026
|
MichaReiser
previously requested changes
Aug 20, 2026
Member
|
Thank you for looking into this |
CPython forbids assigning to or deleting `__debug__` when accessed as an attribute (`x.__debug__`). Attribute assignment is a `SyntaxError` on all supported versions, but attribute deletion only became one in Python 3.14. This change extends `WriteToDebugKind::Delete` with a `removed_in` field so the diagnostic message reports the version-specific removal, and factors the shared `Store`/`Del` dispatch used by both the `Name` and `Attribute` checks into a single `write_to_debug` helper. Closes part of astral-sh#17412.
Sacrimento
force-pushed
the
syntax-error-debug-attribute
branch
from
August 31, 2026 21:41
2fb9008 to
c76b78a
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
MichaReiser
removed their request for review
September 23, 2026 06:59
ntBre
approved these changes
Nov 3, 2026
ntBre
left a comment
Contributor
There was a problem hiding this comment.
Thank you! I made a few simplifications in line with my review comments, but this looked good to me overall.
16 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ruff currently flags assigning to or deleting
__debug__when it's a bare name (__debug__ = False,del __debug__), but not when it's an attribute target (x.__debug__ = False,del x.__debug__).CPython forbids both assigning to
x.__debug__(SyntaxErroron every supported Python version) and deletingx.__debug__only became aSyntaxErrorin Python 3.14.This PR extends the existing
__debug__check toExpr::Attributetargets, gated on the target Python version for the deletion case.Part of #17412.
Test Plan
Added inline test_err/test_ok fixtures alongside the new
Expr::AttributecheckCross-checked the version gating logic and errors against real CPython 3.12/3.13/3.14.