[Python-Dev] __objclass__ documentation
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