bpo-36922: implement PEP-590 Py_TPFLAGS_METHOD_DESCRIPTOR (GH-13338)

Co-authored-by: Mark Shannon <mark@hotpy.org>
This commit is contained in:
Jeroen Demeyer 2019-05-28 14:42:53 +02:00 committed by Petr Viktorin
parent 0811f2d81a
commit eb65e2443a
10 changed files with 132 additions and 7 deletions

View file

@ -1045,6 +1045,32 @@ and :c:type:`PyType_Type` effectively act as defaults.)
???
.. data:: Py_TPFLAGS_METHOD_DESCRIPTOR
This bit indicates that objects behave like unbound methods.
If this flag is set for ``type(meth)``, then:
- ``meth.__get__(obj, cls)(*args, **kwds)`` (with ``obj`` not None)
must be equivalent to ``meth(obj, *args, **kwds)``.
- ``meth.__get__(None, cls)(*args, **kwds)``
must be equivalent to ``meth(*args, **kwds)``.
This flag enables an optimization for typical method calls like
``obj.meth()``: it avoids creating a temporary "bound method" object for
``obj.meth``.
.. versionadded:: 3.8
**Inheritance:**
This flag is never inherited by heap types.
For extension types, it is inherited whenever
:c:member:`~PyTypeObject.tp_descr_get` is inherited.
.. XXX Document more flags here?