| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
Something strange happened here (or maybe the comment was deleted), but here is an interesting note to make: because of how NamedTuple behaves at runtime (just making a collectios.namedtuple) it implements corresponding protocols already at the class level, for example: @runtime
class P(Protocol):
x: int
class N(NamedTuple):
x: int
assert issubclass(N, P) # OK |
Sorry, something went wrong.
|
I left a comment that I realized was completely incorrect so I deleted it |
Sorry, something went wrong.
|
I will soon make another PR that will add (simplified) Protocol to typing_extensions. We cannot add I will keep this PR open (and update depending on the outcome of experiments with typing_extensions). |
Sorry, something went wrong.
|
So IIUC we should first merge #464 and defer this one until the PEP has been accepted, right? |
Sorry, something went wrong.
Yes, also if there will be something we discover while playing with typing_extensions, I will update this PR accordingly (actually there are already few minor tweaks that I need to make here following the review of #464). |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fixes #11
This is a runtime implementation of protocols as per draft PEP 544. (The mypy counterpart is python/mypy#3132)
The implementation is straightforward (mostly I just made current version to behave more similar to __subclasshook__ in collections.abc and added support for __annotations__ in Python 3.6).
Nevertheless, I add a lot of tests. Some of them may look trivial, but previous experience with generics shows that it is better to have them.
There is probably only one corner case worth noting. Consider this situation with for variable annotations:
Then I propose the following subclass check results:
The first one is probably obvious, the second one returns False to make this safe:
The last one although safe since one cannot instantiate protocols, and this is probably what one would expect.
Attn: @JukkaL @ambv @gvanrossum