In #Python >= 3.8, this code raises "TypeError: Cannot inherit from plain Generic":

class Foo(typing.Generic):

but this one works:

class Protocol(typing.Generic):


@bram @val Dug up the git blame to find this PEP:

Seems intended to extend "nominal subtyping" to "structural subtyping (static duck typing)". I don't understand what it means from the abstract... It's a long PEP. Maybe something for later.

@ashwinvis @bram Yeah, Protocols are cool. Basically it's like a Rust trait or a C++ interface; a class is said to implement a Protocol if it implements all the methods in it (it doesn't even need to inherit it to be considered a subclass).

For example, Iterable is a Protocol, which requires classes to implement a __iter__ method.

Sign in to participate in the conversation
Mastodon @ SUNET

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!