-
Notifications
You must be signed in to change notification settings - Fork 16
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
dataclasses requiring InitVar/ClassVar at runtime #83
Comments
I agree, we should add handling for this 👍 Do you think it makes sense to just ignore Would you be interested in creating a fix for this? |
From the dataclasses documentation it appears that it will evaluate |
I started looking at this, but I'm no longer able to replicate the issue after v2. v2 changes the plugin behaviour so that we won't flag imports like from my_app.some_file import dataclass # bad import
from dataclasses import InitVar But this doesn't seem worth handling. The Are you able to still replicate the issue? If not, I think we might consider this resolved, accidentally 🙂 |
I'll close this for now. Please let me know if you still think there's an issue 👍 |
Sorry I was sick yesterday and wasn't at my computer. |
No worries! Thanks for checking 🙂 |
As per https://docs.python.org/3/library/dataclasses.html#class-variables and https://docs.python.org/3/library/dataclasses.html#init-only-variables dataclass() inspects the type of a field in order to treat those types in some special way.
Code like their example (with imports added):
Will throw TC002 on the import of InitVar.
But if InitVar is moved into a type checking block then initializing C will fail because database won't exist in the post_init function.
I imagine the only way to handle this (other than my current solution of a noqa anywhere I use InitVar) will to add exceptions for InitVar and ClassVar if dataclass is also imported or something along those lines ?
The text was updated successfully, but these errors were encountered: