GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||
GeezerVison is showing github.com — Protocols by ilevkivskyi · Pull Request #417 · python/typing Conversation
Member
Fixes #11 This is a runtime implementation of protocols as per draft PEP 544. (The The implementation is straightforward (mostly I just made current version to behave more similar to There is probably only one corner case worth noting. Consider this situation with for variable annotations: @runtime class Proto(Protocol): attr: int class OtherProto(Protocol): attr: int class BadConcrete: attr: int class GoodConcrete: attr = 1 Then I propose the following subclass check results: issubclass(GoodConcrete, Proto) == True issubclass(BadConcrete, Proto) == False # This is a bit questionable, maybe return True? issubclass(OtherProto, Proto) == True The first one is probably obvious, the second one returns if issubclass(BadConcrete, Proto): BadConcrete().attr The last one although safe since one cannot instantiate protocols, and this is probably what one would expect. Attn: @JukkaL @ambv @gvanrossum
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Merged
|
There was an error while loading. Please reload this page.
|
Something strange happened here (or maybe the comment was deleted), but here is an interesting note to make: because of how @runtime class P(Protocol): x: int class N(NamedTuple): x: int assert issubclass(N, P) # OK |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I left a comment that I realized was completely incorrect so I deleted it |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I will soon make another PR that will add (simplified) I will keep this PR open (and update depending on the outcome of experiments with |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
So IIUC we should first merge #464 and defer this one until the PEP has been accepted, right? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Yes, also if there will be something we discover while playing with |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This was superseded by #649 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Protocols (a.k.a. structural subtyping)
There was an error while loading. Please reload this page.