Datasette currently has a few API internals that return sqlite3.Row objects. I was thinking about how this might work in the future - if Datasette ever expands beyond SQLite (plugin-provided backends for PostgreSQL and DuckDB for example) I'd want a way to return data from other stores using objects that behave like sqlite3.Row but are not exactly that class.
The key part is this:
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.
It’s amazing how often people celebrate some new feature in a language and I’m like: TypeScript has been doing this for years now.
[Edit: This is also how interfaces work in Go, and it’s just the old advice “Code against interfaces, not classes.”]
It’s almost like python and typescript are used by different people for different purposes and have therefor developed differently, but some features end up being an overall good idea which enrich their respective ecosystems.
You sound like an absolute tool.
[Edit: Who f*cking cares]
Whatever another programming language supports or does is entirely irrelevant if what you’re working with is Python.