-
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
[flake8-type-checking
] Avoid false positives for |
in TC008
#15201
[flake8-type-checking
] Avoid false positives for |
in TC008
#15201
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
TC008 | 2 | 0 | 2 | 0 | 0 |
This comment was marked as resolved.
This comment was marked as resolved.
c5ad656
to
89d35c2
Compare
@MichaReiser @AlexWaygood You should be able to review this now |
The ecosystem results make sense to me now. Since airflow targets Python 3.9+ mypy would flag those type aliases if they were unquoted. So a TC008 shouldn't trigger, despite there being no runtime effects. |
I've got some false positives that seem to be this, in combination with being in a Should I open an issue for this? |
@dangotbanned Yes, that's this bug, it can also be hit in different contexts, it just previously wasn't as likely to be hit in Feel free to open an issue, if you think it makes it easier for others to discover that this issue is known and will be fixed. |
All good, thanks for clarifying @Daverball 🙂 |
@MichaReiser @AlexWaygood Bumping this again, now that the 0.9 rush is over. |
Thanks for the ping. We decided that Alex should spend more time on Red Knot which leaves me as the main reviewer. I'll try to take a look but I'm not sure when I'll get to it because it also requires familiarizing myself with the type checking rules. Sorry for the long wait. |
@MichaReiser Alright, no worries. This PR should be fairly easy to review, even with surface knowledge, the only thing you need to know is that the union syntax However type checkers still allow you to use the new syntax in older Python versions in non-runtime contexts like implicit/explicit forward references. But type checkers generally don't consider statements in There is a tiny bit of extra complexity for avoiding false negatives for TLDR: Annotated type alias value expressions always need to be considered in runtime context, unless they're explicitly wrapped in quotes. As a consequence, if a forward reference in the value expression uses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detailed explanation! It helped me to build the necessary context quickly to review the PR. I really appreciate it.
Looks good and thanks again for taking the time to explain the changes in detail to me.
This is a follow-up to #15180
Summary
|
is not a valid runtime operation between types pre Python 3.10, so we should avoid unquoting the type expression.Additionally most type checkers don't care about the execution context, so while they will allow
|
between types in stub files for convenience, they will still disallow it in type checking blocks, since those are treated as regular runtime code.Test Plan
cargo nextest run