-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[flake8-type-checking] Fix TC003 false positive with future-annotations
#21125
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
Conversation
…tations` Summary -- Fixes #21121 by upgrading `RuntimeEvaluated` annotations like `dataclasses.KW_ONLY` to `RuntimeRequired`. We already had special handling for `TypingOnly` annotations in this context but not `RuntimeEvaluated`. Combining that with the `future-annotations` setting, which allowed ignoring the `RuntimeEvaluated` flag, led to the reported bug where we would try to move `KW_ONLY` into a `TYPE_CHECKING` block. Test Plan -- A new test based on the issue
|
|
I should have waited a second longer before taking it out of draft. I think the ecosystem hit is a false positive, taking a closer look now. |
|
It looks like we have 4 pre-existing UP037 false positives on this project: but this PR adds a fifth. |
the new 3.13 test shows no diagnostic because both of these are required at
runtime, while the new 3.14 snapshot doesn't change. both of these are allowed
on 3.14 (or with __future__ annotations)
```shell
$ uvx python@3.13 <<EOF
class C:
c: C
EOF
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in C
NameError: name 'C' is not defined
$ uvx python@3.13 <<EOF
from __future__ import annotations
class C:
c: C
EOF
$ uvx python@3.14 <<EOF
from __future__ import annotations
class C:
c: C
EOF
$
```
|
Now the ecosystem check looks good! We needed to visit the whole |
* origin/main: (21 commits) [ty] Update "constraint implication" relation to work on constraints between two typevars (#21068) [`flake8-type-checking`] Fix `TC003` false positive with `future-annotations` (#21125) [ty] Fix lookup of `__new__` on instances (#21147) Fix syntax error false positive on nested alternative patterns (#21104) [`pyupgrade`] Fix false positive for `TypeVar` with default on Python <3.13 (`UP046`,`UP047`) (#21045) [ty] Reachability and narrowing for enum methods (#21130) [ty] Use `range` instead of custom `IntIterable` (#21138) [`ruff`] Add support for additional eager conversion patterns (`RUF065`) (#20657) [`ruff-ecosystem`] Fix CLI crash on Python 3.14 (#21092) [ty] Infer type of `self` for decorated methods and properties (#21123) [`flake8-bandit`] Fix correct example for `S308` (#21128) [ty] Dont provide goto definition for definitions which are not reexported in builtins (#21127) [`airflow`] warning `airflow....DAG.create_dagrun` has been removed (`AIR301`) (#21093) [ty] follow the breaking API changes made in salsa-rs/salsa#1015 (#21117) [ty] Rename `Type::into_nominal_instance` (#21124) [ty] Filter out "unimported" from the current module [ty] Add evaluation test for auto-import including symbols in current module [ty] Refactor `ty_ide` completion tests [ty] Render `import <...>` in completions when "label details" isn't supported [`refurb`] Preserve digit separators in `Decimal` constructor (`FURB157`) (#20588) ...
Summary
Fixes #21121 by upgrading
RuntimeEvaluatedannotations likedataclasses.KW_ONLYtoRuntimeRequired. We already had special handling forTypingOnlyannotations in this context but notRuntimeEvaluated. Combiningthat with the
future-annotationssetting, which allowed ignoring theRuntimeEvaluatedflag, led to the reported bug where we would try to moveKW_ONLYinto aTYPE_CHECKINGblock.Test Plan
A new test based on the issue