On Wed, Aug 5, 2020 at 7:06 PM Steven D'Aprano <st...@pearwood.info> wrote:

> *blinks*
>
> When did this happen?
>
> I'm on Python-Ideas, Python-Dev, and I get announcements of new issues
> on the bug tracker, and I don't recall ever seeing this feature
> discussed.
>

Oddly I barely recall it either, even though according to PEP 487 it was
posted five times to python-dev, and I approved it. It's a long time ago
though (two retirements, for me :-).


> [looks up the docs]
>
> Okay, apparently it was added in 3.6. But the documentation says:
>
>
> """
> When using the default metaclass type, or any metaclass that ultimately
> calls type.__new__, the following additional customisation steps are
> invoked after creating the class object:
>
> first, type.__new__ collects all of the descriptors in the class
> namespace that define a __set_name__() method;
> """
>
> https://docs.python.org/3/reference/datamodel.html#class-object-creation
>
> but that's not what is happening here, since my_property is not a
> descriptor, it's just an arbitrary instance.
>
> (To be a descriptor, it needs to have `__get__` and/or `__set__`
> methods.)
>
> Have I missed something or does this need a documentation fix?
>

That's a good observation. I think the PEP was only thinking of
descriptors, and the implementation possibly took a shortcut by calling
`__set_name__` on every attribute. Or perhaps the PEP was ambiguous, since
under proposal, item (2) states that the "hook is called on all the
attributes (descriptors) defined in the class".

Now there's a general rule that says "if you use a dunder in a way that's
undocumented, the behavior is undefined" (and this includes making up your
own dunders), which means that technically the implementation could do
whatever it wants -- but since this is Python we probably want to accept
that it's called for every attribute, whether it smells like a descriptor
or not, and it would be nice to fix the docs.

Do you have the powers to submit PRs these days?

-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/XCIFYOJQZLKWVG4Z3I4SWYRO6GGSVZQ4/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to