-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Protocol checking against typing_extenstion.Protocol
fails
#479
Comments
typing_extenstion.Protocol
fails
Does Mypy pass your code in strict mode? |
Looks like it: ❯ mypy --version [12:51:41]
mypy 1.11.2 (compiled: yes)
❯ mypy --strict tests/exp.py [12:51:45]
Success: no issues found in 1 source file |
Yeah, I recall something like this was reported before. I'll get it fixed for the next release, but I'm currently busy trying to make new releases in two other projects. I'll tackle typeguard after that. |
@agronholm If we agree on an approach here i'm happy to contribute a PR. Would the solution be using |
This is not specific to # typedmod.py
import typing as t
T_co = t.TypeVar("T_co", covariant=True)
class Empty(t.Protocol):
pass
class GenericEmpty(t.Protocol[T_co]):
pass
def takes_empty(it: Empty) -> None:
pass
def takes_generic_empty(it: GenericEmpty[T_co]) -> None:
pass When using them in a terminal session:
What this suggests is that you could use the attributes of an empty protocol (like |
Actually, upon further research, the solution might be simpler: use |
Typeguard already has a hard dependency on |
This will be fixed with #490. |
This was fixed in v4.4.0. |
Things to check first
I have searched the existing issues and didn't find my bug already reported there
I have checked that my bug is still present in the latest release
Typeguard version
4.3.0
Python version
Python 3.10.4
What happened?
Expected typeguard to ignore private attributes of the
typing_extension.Protocol
so that type checking would pass.How can we reproduce the bug?
Running the above program will result in:
typeguard.TypeCheckError: __main__.DefaultDo is not compatible with the IDo protocol because it has no attribute named '__protocol_attrs__'
Indeed, extending the
typing_extensions.Protocol
adds the__protocol_attrs__
attribute and causes the mismatch. I did notice however that typeguard has provisions to ignore private attributes of thetyping.Protocol
class:typeguard/src/typeguard/_checkers.py
Lines 668 to 671 in 016f813
So I was thinking this might be extended to support
typing_extension.Protocol
? If not, it would be great if we had some way to inject custom attributes we'd like typeguard to ignore.The text was updated successfully, but these errors were encountered: