Argument Clinic: document converters for getters and setters - #1887
Argument Clinic: document converters for getters and setters#1887serhiy-storchaka wants to merge 3 commits into
Conversation
Use _ssl._SSLContext.check_hostname as the main example.
Documentation build overview
|
| 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``. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Documents the changes in python/cpython#156066, and should be merged after it.
The value of a
@settercan be declared as a parameter with a converter, and a@gettercan 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_hostnameis used as the main example instead of_io.TextIOWrapper._CHUNK_SIZE, because it uses converters, andfunction.__type_params__is used as the example of@deleter.