12
Protocols in Python (til.simonwillison.net)
you are viewing a single comment's thread
view the rest of the comments
[-] rglullis@communick.news 5 points 1 year ago

The key part is this:

it turns out protocols really are just a formalization of Python's duck typing.

Meaning, this is just a way to say that if you are defining some system that needs to conform with some interface, you can have type checked even if your have different objects from different classes. No need for TypeVar or define a crazy hierarchy: as long as the types implements the methods defined by the Protocol, the type checker will be happy.

this post was submitted on 26 Jul 2023
12 points (100.0% liked)

Python

6400 readers
9 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