Handles type checks for Type[Protocol] - #251
Conversation
|
Hey @agronholm , could you take a look at this PR? As this would be needed in testslide facebook/TestSlide#333. |
4be6e31 to
4da33fb
Compare
|
The 2.x series (current master) has been frozen for new features; you should rebase this against the 3.0 branch. |
|
I've merged the 3.0 branch to master now to prevent any further confusion. |
4da33fb to
a3e2e17
Compare
Handles type checks for Type[Protocol]
6e81b40 to
16dd3c4
Compare
|
@agronholm Thanks for helping out with the 3.0 rebase! I've updated my PR and made sure all signals are green. Let me know if there's anything else you'd like me to address for this PR |
|
Looks good at a glance; I will do a more thorough review later. |
|
This PR confuses me. You seem to be dropping type checking support for static protocols. Why? |
|
Static protocols were never supported by Typeguard. See line 501 of _checkers.py: StaticProtocol is defined without The main fix in the PR is the addition of check_protocol in the |
|
To be more specific, I've made sure that the the type checker can detect not only that the instance There were no changes made to the how Typeguard handles |
|
Does this help clarify the PR? |
agronholm
left a comment
There was a problem hiding this comment.
Looks good, just one tiny nit.
|
Thanks! |
|
Thanks for updating the lint and accepting the PR! |
I noticed that typeguard wasn't able to correctly type check passed in classes when the type hint was a Type[Protocol]. You would receive an error like:
TypeError: Protocols with non-method members don't support issubclass(). Using isinstance() in these situations would be able to correctly type check the passed in class. I also added a warning when a Protocol wasn't annotated with runtime_checkable to make it more explicit when typeguard was unable to perform type checking.Tests:
Added a data protocol to improve coverage
Added a test for checking Type[Protocol]