Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Fixes #11
This is a runtime implementation of protocols as per draft PEP 544. (The
mypycounterpart is python/mypy#3132)The implementation is straightforward (mostly I just made current version to behave more similar to
__subclasshook__incollections.abcand 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
Falseto 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