Skip to content

gh-113318: Support @deleter as a separate function in Argument Clinic - #157815

Draft
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-113318-getset-deleter
Draft

serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-113318-getset-deleter

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Sep 19, 2026

Copy link
Copy Markdown
Member

Used alone, the @deleter directive defines a function which deletes the attribute. It can be combined with a @setter defined in a separate block: the setter slot of the PyGetSetDef entry is then filled with a generated dispatcher which calls the setter or the deleter depending on whether the value is NULL.

/*[clinic input]
@setter
Test.settable_deletable
    value: int
[clinic start generated code]*/

/*[clinic input]
@deleter
Test.settable_deletable
[clinic start generated code]*/

The two impl functions get distinct C names (..._set_impl and ..._del_impl), so neither has to handle the other's case, and a setter that has a separate deleter no longer contains a dead if (arg == NULL) check for a case that the dispatcher never passes to it.

function.__annotations__ is converted as the first user: the deleter is a separate @deleter block, and the setter is left with only the None-or-dict logic.

There are now 36 @setter and 6 @deleter uses in the tree. 30 setters reject deletion with the generated AttributeError, 5 are combined with @deleter in the same block and handle NULL themselves (frame.f_trace, _ctypes.CType_Type.__pointer_type__, _ctypes.CFuncPtr.errcheck, .restype, .argtypes), and function.__annotations__ uses the new separate @deleter.

…Clinic

Used alone, the @deleter directive defines a function which deletes the
attribute.  It can be combined with a @Setter defined in a separate block:
the setter slot of the entry is then filled with a function which dispatches
to one of them depending on whether the value is NULL.
function.__annotations__ is now implemented in this way.
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.

1 participant