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

That still doesn't explain why duck typing is ever a thing beyond "I'm too lazy to write extends BaseClass". There's simply no reason to want it.

[-] lysdexic@programming.dev 1 points 1 year ago

I already explained it to you: protocols apply to types you do not own or control, let alone can specify a base class.

You just specify a protocol, specify that a function requires it, and afterwards you can pass anything to it as-is and you'll be able to validate your calls.

[-] o11c@programming.dev 1 points 1 year ago

and I already explained that Union is a thing.

[-] lysdexic@programming.dev 1 points 1 year ago* (last edited 1 year ago)

I'm not sure you understand that what a union does or does not do is completely irrelevant and besides the point. Python's protocols add support for structural subtyping, and enable both runtime and build-time type checks without requiring major code changes. Don't you understand what that means?

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