<div dir="ltr"><div dir="ltr"><div>(I did see your post in the moderation queue and let it through -- however the mypy team, which would be most responsible for answering your question, has been busy fighting some fires.)<br></div><div><br></div><div>I'm trying to understand what the PEP is saying and how you're interpreting, and I'm not getting very far. I know for a fact that Protocols work great with dunder methods. In fact the very first example in the PEP uses `__len__` and `__iter__`, and there are several other examples using `__iter__`, so I also know that this isn't an accident of mypy's implementation. And mypy knows about the special rules for dunder method lookup.</div><div><br></div><div>So what's left to figure out is what the bullet you quote means, and whether it should be clarified, or whether it is literally correct (about what the implementation does).</div><div><br></div><div>My guess, without delving into the implementation, is that a Protocol is *always* about the class, and that this is entirely a red herring.</div><div><br></div><div>Looking at the implementation (e.g. the Python 3 implementation at <a href="https://github.com/python/typing/blob/master/typing_extensions/src_py3/typing_extensions.py#L1077">https://github.com/python/typing/blob/master/typing_extensions/src_py3/typing_extensions.py#L1077</a>) doesn't give me much clarity. The code seems to be highly optimized and not so readable. But I do see, at line 1159, what looks like the check that the bullet refers to. The point here is simply to make sure that a protocol doesn't inherit from a non-protocol class. Besides `object` there are several other exceptions that appear to me to be related to internals of the runtime typing implementation.</div><div><br></div><div>If you are still not satisfied, I recommend that you try to construct a counter-example and test it against the typing_extensions modules in Python 3.7 or 3.8.</div><div><br></div><div>Thanks!</div><div><br></div><div>--Guido<br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 21, 2019 at 8:40 AM Eric Snow <<a href="mailto:ericsnowcurrently@gmail.com">ericsnowcurrently@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div style="font-family:sans-serif;font-size:12.8px" dir="auto"><div style="margin:15px 0px"><div><div dir="auto"><div dir="auto">[originally I sent this to typing-sig but I guess it got caught up in moderation.]</div><div dir="auto"><br></div><div dir="auto">In PEP 554 [1] it says:</div><div dir="auto"><br></div><div dir="auto"><ul style="margin:0px 0px 1.3125em 1.5em;padding:0px;border:0px none;font-size:16px;line-height:1.875;font-family:"sourcesansproregular","arial",sans-serif;vertical-align:baseline;list-style:outside none square;color:rgb(68,68,68);background-color:rgb(249,249,249)"><li style="margin:0.2625em 0px;padding:0px;border:0px none;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:inherit;line-height:1.65em;font-family:inherit;vertical-align:baseline">Implement metaclass functionality to detect whether a class is a protocol or not. Add a class attribute <tt>_is_protocol = True</tt> if that is the case. Verify that a protocol class only has protocol base classes in the MRO (except for object). </li></ul></div><div dir="auto">The phrase "except for object" implies that having "type" in the MRO would not be allowed.  Was that intentional?</div><div dir="auto"><br></div><div dir="auto">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?</div><div dir="auto"><br></div><div dir="auto">Thanks for working on this, BTW.  It's a nice addition. :)</div><div dir="auto"><br></div><div dir="auto">-eric</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto">[1] <a href="https://www.python.org/dev/peps/pep-0544/#implementation-details" style="text-decoration-line:none;color:rgb(66,133,244)" rel="noreferrer noreferrer" target="_blank">https://www.python.org/dev/peps/pep-0544/#implementation-details</a></div></div></div></div></div></div>
_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/guido%40python.org" rel="noreferrer" target="_blank">https://mail.python.org/mailman/options/python-dev/guido%40python.org</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div><div><i style="font-family:Arial,Helvetica,sans-serif;font-size:small;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);color:rgb(136,136,136)"><span>Pronouns</span>: he/him/his </i><a href="http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/" style="color:rgb(17,85,204);font-family:Arial,Helvetica,sans-serif;font-size:small;font-style:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255)" target="_blank"><i>(why is my <span>pronoun</span> here?)</i></a></div></div></div>