Skip to content

gh-113318: Fix @getter and @setter in Argument Clinic - #155778

Merged
serhiy-storchaka merged 2 commits into
python:mainfrom
serhiy-storchaka:gh-113318-getset-bugfix
Aug 18, 2026
Merged

gh-113318: Fix @getter and @setter in Argument Clinic#155778
serhiy-storchaka merged 2 commits into
python:mainfrom
serhiy-storchaka:gh-113318-getset-bugfix

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

Three fixes for the accessors generated by Argument Clinic:

  • Generating a @getter or a @setter in a preprocessor conditional block failed with KeyError: 'methoddef_name', because the fallback definition was emitted for the METHODDEF symbol instead of the GETSETDEF one.
  • The entry of PyGetSetDef is identified by the C basename shared by the accessors, so defining them with different C basenames (Foo.p as foo_get and Foo.p as foo_set), or defining the same accessor twice, silently generated invalid or duplicated entries. It is now an error.
  • The setter was called with NULL to delete the attribute. Implementations which did not check for it crashed -- frame.f_trace_opcodes and the context, owner and session attributes of _ssl._SSLSocket -- or reported a confusing SystemError. Deletion is now rejected with AttributeError, unless the new directive @deleter is applied to the setter, which is then called with NULL as before.

@deleter is applied to the 22 setters whose implementation is written to accept NULL, so deleting these attributes works as before. Only three generated files change: the setters of _ssl, _sqlite3.Cursor.arraysize and frame.f_trace_opcodes gain the deletion check.

Fix generating an accessor in a preprocessor conditional block.
Reject the accessors of the same attribute with different C basenames and
the same accessor defined twice.
Reject deletion of the attribute, which crashed the setter, unless the new
directive @deleter is applied to it.
They raised AttributeError for deletion, and this is now done by the
generated code.
@serhiy-storchaka

Copy link
Copy Markdown
Member Author

Removed @deleter from 7 setters which check for NULL themselves and raise AttributeError.

@serhiy-storchaka
serhiy-storchaka enabled auto-merge (squash) August 18, 2026 07:57
@serhiy-storchaka serhiy-storchaka changed the title gh-113318: Fix @getter and @setter in Argument Clinic Aug 18, 2026
@serhiy-storchaka serhiy-storchaka changed the title Fix @getter and @setter in Argument Clinic Aug 18, 2026
@serhiy-storchaka
serhiy-storchaka merged commit 915970c into python:main Aug 18, 2026
67 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@serhiy-storchaka
serhiy-storchaka deleted the gh-113318-getset-bugfix branch August 18, 2026 12:35
@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.15 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 915970ce9d031388a2bcf3e9f6199fa3e0eb9ebd 3.15
@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 915970ce9d031388a2bcf3e9f6199fa3e0eb9ebd 3.14
@bedevere-app

bedevere-app Bot commented Aug 18, 2026

Copy link
Copy Markdown

GH-156010 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Aug 18, 2026
@bedevere-app

bedevere-app Bot commented Aug 18, 2026

Copy link
Copy Markdown

GH-156011 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Aug 18, 2026
@bedevere-app

bedevere-app Bot commented Aug 18, 2026

Copy link
Copy Markdown

GH-156012 is a backport of this pull request to the 3.13 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant