-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Failing to recognize generic constraints in tuples #7702
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
Comments
This is probably because you're missing a type argument to The |
@JelleZijlstra Thanks for the flag tip. I'm trying your suggestion, but here with correct pairings:
Error message from mypy:
|
Interesting, that seems like a bug to me. |
Mypy treats a type variable in the return type (but not in an argument type) as meaning that the value of that variable is specified by the calling context. A typical example is |
The basic context here is I need to map data into different shapes using various
Mapping
s, and then write those shapes to different targets using variousWriter
s. I want to ensure that when I define a job configuration, I get aMapping
andWriter
that are compatible with one another (i.e. they map to and write the same shape).Initially I tried returning a
Tuple[Mapping[E], Writer[E]]
, but found that mypy does not report an error when I deliberately mismatch aMapping
andWriter
. Fortunately, however, an error is raised when I define a (data)class to hold these two objects instead of just a tuple. I think using a dataclass here is probably a good idea regardless (for reader comprehension purposes), but I would nevertheless expect the tuple implementation to behave the same way. It seems like someone could try the tuple implementation, not see any errors, and incorrectly assume they have a typechecking safety net that isn't actually there.What is the actual behavior/output?
Mypy only errors on the dataclass implementation, not the tuple implementation
What is the behavior/output you expect?
The tuple implementation should report an error as well
What are the versions of mypy and Python you are using?
mypy = "==0.720"
python version 3.7.4
What are the mypy flags you are using? (For example --strict-optional)
None
The text was updated successfully, but these errors were encountered: