[Python-Dev] PEP 544: Protocols (original) (raw)
Matthias Kramm kramm at google.com
Tue Mar 21 12:09:31 EDT 2017
- Previous message (by thread): [Python-Dev] PEP 544: Protocols
- Next message (by thread): [Python-Dev] PEP 544: Protocols
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, Mar 20, 2017 at 2:42 PM, Ivan Levkivskyi <levkivskyi at gmail.com> wrote:
1. Backward compatibility: People are already using ABCs, including generic ABCs from typing module. If we prohibit explicit subclassing of these ABCs, then quite a lot of code will break.
Fair enough. Backwards compatibility is a valid point, and both abc.py and typing.py have classes that lend itself to becoming protocols.
The one thing that isn't clear to me is how type checkers will distinguish between 1.) Protocol methods in A that need to implemented in B so that B is considered a structural subclass of A. 2.) Extra methods you get for free when you explicitly inherit from A.
To provide a more concrete example: Since Mapping implements eq, do I also have to implement eq if I want my class to be (structurally) compatible with Mapping?
If you think it makes sense to add a note that implicit subtyping is preferred (especially for user defined protocols), then this certainly could be done.
Yes, I believe it would be good to mention that. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20170321/fb6d825c/attachment.html>
- Previous message (by thread): [Python-Dev] PEP 544: Protocols
- Next message (by thread): [Python-Dev] PEP 544: Protocols
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]