Skip to content

Argument Clinic: document converters for getters and setters - #1887

Draft
serhiy-storchaka wants to merge 3 commits into
python:mainfrom
serhiy-storchaka:clinic-getset-converters
Draft

Argument Clinic: document converters for getters and setters#1887
serhiy-storchaka wants to merge 3 commits into
python:mainfrom
serhiy-storchaka:clinic-getset-converters

Conversation

@serhiy-storchaka

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

Copy link
Copy Markdown
Member

Documents the changes in python/cpython#156066, and should be merged after it.

The value of a @setter can be declared as a parameter with a converter, and a @getter can define a return converter.
The accessors of an attribute are now identified by its Python name, so they can use different C basenames and can be defined several times in mutually exclusive preprocessor conditional blocks.

_ssl._SSLContext.check_hostname is used as the main example instead of _io.TextIOWrapper._CHUNK_SIZE, because it uses converters, and function.__type_params__ is used as the example of @deleter.

Use _ssl._SSLContext.check_hostname as the main example.
@read-the-docs-community

read-the-docs-community Bot commented Aug 20, 2026

Copy link
Copy Markdown

Documentation build overview

📚 CPython devguide | 🛠️ Build #34153687 | 📁 Comparing be59e6f against latest (708aa7c)

  🔍 Preview build  

2 files changed
± versions/index.html
± development-tools/clinic/howto/index.html

Comment thread development-tools/clinic/howto.rst Outdated
Comment on lines +1523 to +1525
The value is only converted if the attribute is not deleted, so it must have
a default value, which the "impl" function receives for the deletion.
The implicitly declared value gets the default ``NULL``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IMO, this is too confusing. The connection between default and placeholder for del is not obvious.
An if (value=NULL) inside the function covers all the use cases and is much clearer. Can we disallow arbirtary defaults (or enforce using NULL) here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If we use converter such as int, we cannot use if (value=NULL) inside the function. For now, there are no such examples in the CPython code, but we can add them in future.

If deletion is equivalent to setting to None or other value, we can use it as the default value and remove a special case from function. For now there are no examples which do not store NULL internally.

So practically all current examples use NULL as default value. But adding additional restriction on the default value will only complicate the code and unnecessary restrict the future use.

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.

2 participants