Skip to content

Conversation

@ntBre
Copy link
Contributor

@ntBre ntBre commented Oct 29, 2025

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

ntBre added 3 commits October 29, 2025 10:47
…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
@ntBre ntBre added the bug Something isn't working label Oct 29, 2025
@ntBre ntBre marked this pull request as ready for review October 29, 2025 15:03
@ntBre ntBre requested a review from MichaReiser October 29, 2025 15:03
@github-actions
Copy link
Contributor

github-actions bot commented Oct 29, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@ntBre ntBre marked this pull request as draft October 29, 2025 15:16
@ntBre
Copy link
Contributor Author

ntBre commented Oct 29, 2025

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.

@ntBre
Copy link
Contributor Author

ntBre commented Oct 29, 2025

It looks like we have 4 pre-existing UP037 false positives on this project:
src/latch/ldata/_transfer/upload.py:121:27: UP037 [*] Remove quotes from type annotation
src/latch/ldata/_transfer/upload.py:122:33: UP037 [*] Remove quotes from type annotation
src/latch/ldata/_transfer/upload.py:132:28: UP037 [*] Remove quotes from type annotation
src/latch/types/directory.py:162:36: UP037 [*] Remove quotes from type annotation

but this PR adds a fifth.

ntBre added 2 commits October 29, 2025 12:13
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
$
```
@ntBre
Copy link
Contributor Author

ntBre commented Oct 29, 2025

Now the ecosystem check looks good! We needed to visit the whole RuntimeEvaluated annotation as RuntimeRequired for the special dataclass types, unlike the existing TypingOnly branch, which could treat the annotation and slice separately.

@ntBre ntBre marked this pull request as ready for review October 29, 2025 16:47
@MichaReiser MichaReiser requested a review from amyreese October 29, 2025 21:38
@ntBre ntBre merged commit 1c7ea69 into main Oct 30, 2025
37 checks passed
@ntBre ntBre deleted the brent/future-annotations-kw-only branch October 30, 2025 18:14
dcreager added a commit that referenced this pull request Oct 30, 2025
* 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)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TC003 false-positive for dataclass.KW_ONLY when future-annotations is true

3 participants