Skip to content

gh-113318: Better implementation of @getter and @setter in Argument Clinic - #156066

Open
serhiy-storchaka wants to merge 5 commits into
python:mainfrom
serhiy-storchaka:gh-113318-getset-rework
Open

gh-113318: Better implementation of @getter and @setter in Argument Clinic#156066
serhiy-storchaka wants to merge 5 commits into
python:mainfrom
serhiy-storchaka:gh-113318-getset-rework

Conversation

@serhiy-storchaka

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

Copy link
Copy Markdown
Member

Follow-up to GH-155778.

  • The value of a @setter is now a parameter, so it can use a converter, and a @getter can define a return converter. It is optional to declare the value: value: object is added implicitly, with the default NULL if @deleter is applied.
  • The accessors of an attribute are now collected in a Property, indexed by the Python name, so the entry of PyGetSetDef is identified by the Python name instead of the C basename. The accessors can therefore use different C basenames, and several implementations of the same accessor can be defined in different preprocessor conditional blocks.
  • The entry is composed when all blocks of the file are rendered, instead of by the preprocessor. Half-macros are only generated for an accessor which is compiled conditionally, which removes about 1000 lines from the generated files.

Some setters and getters of _ssl, _asyncio, _ctypes, _sqlite3 and function.__type_params__ now use converters. The error for a wrong type of the value names the attribute instead of an argument of a function:

TypeError: attribute 'verify_mode' must be int, not str
…ment Clinic

The value of a @Setter is now a parameter, which can use a converter,
and a @Getter can define a return converter.  Declaring the value is
optional.

The accessors of an attribute are now collected in a Property, so the
entry of PyGetSetDef is identified by the Python name instead of the C
basename, and is composed without the help of the preprocessor unless
some accessor is compiled conditionally.
…set-rework

# Conflicts:
#	Tools/clinic/libclinic/dsl_parser.py
#	Tools/clinic/libclinic/parse_args.py
@encukou

encukou commented Aug 20, 2026

Copy link
Copy Markdown
Member

Thanks.

I won't have time this week for a line-by-line review, but at first glance this looks good.

…set-rework

# Conflicts:
#	Modules/_sqlite/cursor.c
#	Modules/clinic/_ssl.c.h
#	Tools/clinic/libclinic/clanguage.py
#	Tools/clinic/libclinic/parse_args.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants