this post was submitted on 13 Jul 2023
9 points (80.0% liked)

Python

6378 readers
110 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

πŸ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
πŸ’“ Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] plistig@feddit.de 3 points 1 year ago* (last edited 1 year ago) (1 children)

Abc and Protocols are not the same, though. The protocol is met when all methods are implemented with the expected signature. Abstract base classes require you to opt in to be considered an Implementation of some interface. Both have different use cases. Protocols are much more fragile.

[–] riskable@programming.dev 1 points 1 year ago (1 children)

I wouldn't say Protocols are more "fragile"... They're more strict.

[–] plistig@feddit.de 1 points 1 year ago

The opposite is true. If you have two interfaces that contain methods with the same name, then they have the same typing.Protocol. It is not possible to specify preconditions or contracts, as you would with abc.