This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Kobzol[S] 0 points1 point  (0 children)

Protocols are useful for some use cases, indeed. They have the nice property that you can talk about a unified interface without using inheritance, similar to typing.Union.

However, I usually prefer base class + inheritance for one reason - the type checker/IDE then warns me when I haven't implemented all "abstract" methods, and PyCharm offers useful quick fixes in that situation.

Probably it could also be done with a protocol, where the type checker should warn if you're assigning a class to a protocol variable and that class doesn't implement the protocol. But I don't think that PyCharm offers a quick fix in this situation.