[Python-Dev] PEP 544 and dunder methods

Eric Snow ericsnowcurrently at gmail.com
Tue May 21 11:35:32 EDT 2019


[originally I sent this to typing-sig but I guess it got caught up in
moderation.]

In PEP 554 [1] it says:


   - Implement metaclass functionality to detect whether a class is a
   protocol or not. Add a class attribute _is_protocol = True if that is
   the case. Verify that a protocol class only has protocol base classes in
   the MRO (except for object).

The phrase "except for object" implies that having "type" in the MRO would
not be allowed.  Was that intentional?

Perhaps I've misunderstood semantics with typing stuff (I haven't followed
much of the discussion), but there seems to be a disconnect with how
special ("dunder") methods are looked up (i.e. on classes).  Effectively,
an object's *class* has to implement the relevant "protocol".  So
disallowing "type" in the MRO means not using the PEP's functionality for
"special method" protocols (as well as metaclasses in general).  Have I
understood that right?  Is that on purpose?

Thanks for working on this, BTW.  It's a nice addition. :)

-eric


[1] https://www.python.org/dev/peps/pep-0544/#implementation-details
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20190521/754f7184/attachment.html>


More information about the Python-Dev mailing list