Skip to content

Set Py_TPFLAGS_METHOD_DESCRIPTOR on PyGIFunctionInfo_Type

James Henstridge requested to merge jamesh/pygobject:method-descr-types into main

This MR sets the Py_TPFLAGS_METHOD_DESCRIPTOR flag on PyGIFunctionInfo_Type, signalling to the interpreter that it's descriptor behaviour matches that of the standard function type and that it is safe to bypass creating a bound method object and call method(self, args...) directly.

At present, the behaviour only matches for FunctionInfo objects representing methods: constructors and non-methods present different descriptor behaviour. I've handled this by removing that code from _function_info_descr_get and have MetaClassHelper._setup_methods wrap constructors and non-methods in classmethod and staticmethod respectively.

These changes should also help the specializing interpreter classify methods better, potentially opening up other optimisation opportunities:

https://github.com/python/cpython/blob/91e64be731fe42e6b252b95d79d900251388bfc6/Python/specialize.c#L776-L786

Merge request reports

Loading