-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Lint when |
annotations contain string segments
#9139
Comments
What was the original annotation? |
The issue here is that you changed |
Yes, it looks like I introduced this error when trying to manually resolve the warning from Ruff, since I didn't realize it was invalid to quote just part of it. I'm surprised Pyright doesn't complain about an invalid annotation. Is it possible to make Ruff complain about it? My original annotation had no quotes in it:
|
We could probably lint against that, yeah. |
TCH
quote-annotations
fixes introduced runtime errors into my tests|
annotations contain string segments
Repurposing the issue to lint against |
## Summary A common mistake is to add quotes around one member in an `X | Y`-style type union, as in: ```python contract_versions_list: list[ContractVersion] | 'QuerySet[ContractVersion]' | None = None ``` However, doing so will lead to a runtime error if the annotation is runtime-evaluated. This PR lints against such patterns. Closes #9139.
This is one of the inputs to my function, after quotes were automatically added (and I manually turned
QuerySet['ContractVersion']
into'QuerySet[ContractVersion]'
due to #9135 and #9136:When I manually changed it to the following, the tests ran fine again:
I'm on Ruff v0.1.8 in a Django 4.2.7 project, running tests with PyTest 7.4.3
The text was updated successfully, but these errors were encountered: