-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
dataclass does not properly support generics #7520
Comments
Yes, this is a bug. The fix is to map/expand variable types in the supertype along the MRO instead of "blindly" copying them to the subtype. Should be not too hard to implement. |
It looks like this is still a problem with the latest release. I think I know how to solve this. I can send a pull request. Also, looks like the same problem affects the attrs plugin (#5744). I think I can fix both with basically the same code. |
I opened PRs to fix:
|
Fixes #7520 Updates the dataclasses plugin. Instead of directly copying attribute type along the MRO, this first resolves typevar in the context of the subtype.
Getting error related to the same issue -- inheritence in generic dataclasses -- If the TypeVar is in another Generic container
The equivalent code without dataclasses using Reported here #10986 Anything that we can do to address it? |
I encountered the same issue as @rusiaaman. His example reproduces in python 3.9.7 |
Open a new bug report with the details. This bug report has been closed. |
Please provide more information to help us understand the issue:
I believe this is a bug.
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
Here is MRE:
Argument "attr" to "Sub" has incompatible type "V"; expected "T"
The code should type check.
Do you see the same issue after installing mypy from Git master?
mypy 0.720
yes, tested against:
8782ae7f789ad5b8cab97d3c8419f9f98b6eb285
The defaults, executed with:
mypy test_script.py
the full traceback below.
The text was updated successfully, but these errors were encountered: