[Python-Dev] objclass documentation (original) (raw)

Nick Coghlan ncoghlan at gmail.com
Sun Oct 13 13:44:06 CEST 2013


On 13 Oct 2013 08:27, "Ethan Furman" <ethan at stoneleaf.us> wrote:

It was pointed in Issue16938[1] that objclass is not documented anywhere. Is the following an appropriate description? (in Doc/reference/datamodel.rst in user-defined functions)

+-------------------------+-------------------------------+-----------+ | :attr:_objclass_ | The class this object belongs | | | | to; useful when the object is | | | | a descriptor, or a virtual or | | | | dynamic class attribute, and | | | | it's class attribute does | | | | not match the class it is | | | | associated with, or it is not | | | | in that class' _dict_. | | +-------------------------+-------------------------------+-----------+

I think this is inaccurate. The meaning of objclass as described in PEP 252 is to denote unbound callable descriptors that only work with a specific type. That's why it's mostly gone in Python 3.

It should be documented, but the documentation should say something like:

objclass: Indicates this callable requires an instance of the given type (or a subclass) as its first positional argument. For example, CPython sets this for unbound methods that are implemented in C rather than Python.

The offending block of code in the inspect module (http://hg.python.org/cpython/file/default/Lib/inspect.py#l366) that prompted http://bugs.python.org/issue16938 just looks flat out broken to me. There's zero reason to expect that class on the result of retrieving an attribute from an object will appear in the MRO for that object. I just missed that detail when reviewing http://bugs.python.org/issue19030 :)

I'll reply on the tracker with some additional details/suggestions.

Cheers, Nick.



More information about the Python-Dev mailing list