Argument clinic: improve generated code for self converter type checks #101409
Labels
performance
Performance or resource usage
topic-argument-clinic
type-feature
A feature request or enhancement
Feature or enhancement
Currently, typically for
__new__
and__init__
methods, Argument Clinic will spell out theself
type check as such:prefix
is a slightly modified variant oftype_object
, depending on if the latter is a pointer. This works swell in most cases, but with module state and heap types, the generated code is not optimal. First, let's just quote the AC docs on how to declare a class:For heap types with module state, you'd typically do something like this:
Currently, this generates clinic code like this:
... potentially calling
PyType_GetModuleByDef
twice in the self type check.Pitch
Suggesting to modify clinic to store the self type pointer in a local variable, and use that variable in the self type check. Proof-of-concept diff from the
_sqlite
extension module clinic codePrevious discussion
#101302 (comment)
Linked PRs
The text was updated successfully, but these errors were encountered: