Skip to content

[flake8-tidy-imports] Stabilize lazy-import-immediately-resolved (TID255) - #28761

Merged
ntBre merged 1 commit into
brent/0.17.0from
brent/stabilize-tid255
Sep 25, 2026
Merged

ntBre merged 1 commit into
brent/0.17.0from
brent/stabilize-tid255

Conversation

@ntBre

@ntBre ntBre commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@ntBre ntBre added the rule Implementing or modifying a lint rule label Sep 21, 2026
@astral-sh-bot

astral-sh-bot Bot commented Sep 21, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+12 -0 violations, +0 -0 fixes in 1 projects; 58 projects unchanged)

scikit-build/scikit-build-core (+12 -0 violations, +0 -0 fixes)

+ src/scikit_build_core/file_api/model/common.py:21:13: TID255 Lazy import `Path` is resolved immediately
+ src/scikit_build_core/file_api/model/common.py:22:12: TID255 Lazy import `Path` is resolved immediately
+ src/scikit_build_core/file_api/model/toolchains.py:18:30: TID255 Lazy import `Path` is resolved immediately
+ src/scikit_build_core/file_api/model/toolchains.py:19:27: TID255 Lazy import `Path` is resolved immediately
+ src/scikit_build_core/file_api/model/toolchains.py:20:36: TID255 Lazy import `Path` is resolved immediately
+ src/scikit_build_core/file_api/model/toolchains.py:21:25: TID255 Lazy import `Path` is resolved immediately
+ src/scikit_build_core/file_api/model/toolchains.py:27:11: TID255 Lazy import `Optional` is resolved immediately
+ src/scikit_build_core/file_api/model/toolchains.py:27:20: TID255 Lazy import `Path` is resolved immediately
+ src/scikit_build_core/file_api/model/toolchains.py:28:22: TID255 Lazy import `Optional` is resolved immediately
+ src/scikit_build_core/file_api/model/toolchains.py:29:9: TID255 Lazy import `Optional` is resolved immediately
+ src/scikit_build_core/file_api/model/toolchains.py:30:14: TID255 Lazy import `Optional` is resolved immediately
+ src/scikit_build_core/file_api/model/toolchains.py:31:13: TID255 Lazy import `Optional` is resolved immediately

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
TID255 12 12 0 0 0

Linter (preview)

✅ ecosystem check detected no linter changes.

@ntBre ntBre closed this Sep 21, 2026
@ntBre ntBre reopened this Sep 21, 2026
@ntBre ntBre mentioned this pull request Sep 21, 2026
2 tasks done
@ntBre
ntBre force-pushed the brent/stabilize-tid255 branch from 1c9c374 to 7435936 Compare September 21, 2026 18:54
@ntBre
ntBre marked this pull request as ready for review September 21, 2026 18:55
@ntBre ntBre mentioned this pull request Sep 21, 2026
27 of 32 tasks
@ntBre ntBre added this to the v0.17 milestone Sep 21, 2026
@ntBre

ntBre commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

The ecosystem results are a little weird here. They point to a slightly surprising interaction between __lazy_modules__ and our target-version handling. scikit-build requires a Python version >=3.9 and are using __lazy_modules__ to backport laziness. The potentially weird part is that we flag the uses of the modules in __lazy_modules__ in annotations, where they wouldn't be immediately resolved if the Python version is high enough for __lazy_modules__ to have any effect... In other words, if __lazy_modules__ actually makes imports lazy (3.15+) then annotations are also deferred (3.14+), even if the configured version is lower.

Entirely coincidentally, Ruff is actually correct in all of these cases because @dataclass does evaluate the annotations, even on 3.14. However, in a case like this, without the decorator, we emit a diagnostic incorrectly on lower Python versions:

__lazy_modules__ = ["pathlib"]

from pathlib import Path

class C:
    path: Path

Python 3.10, diagnostic: https://play.ruff.rs/dd287dcd-8bf7-4e41-90b4-db4665ed0db8

Python 3.14, no diagnostic: https://play.ruff.rs/51dfcc8c-8029-4dfa-8136-a8860818e413

I guess these were probably also present in my __lazy_modules__ PR, but I didn't connect the contradiction until seeing them again today. I'll see if I can fix this separately.

ntBre added a commit that referenced this pull request Sep 22, 2026
…otations (`TID255`) (#28767)

Summary
--

This PR fixes an issue I saw in the ecosystem report for the
stabilization PR
(#28761 (comment)).
In short, we were flagging annotations like this:

```py
__lazy_modules__ = ["pathlib"]

from pathlib import Path

class C:
    path: Path
```

on Python versions before 3.14, even though they are not actually
resolved immediately when
`__lazy_modules__` makes the imports lazy (3.15 > 3.14, as it turns
out).

Because the semantic model checks the target version when setting
`TYPING_ONLY_ANNOTATION`, we
instead check the other two annotation flags:
`RUNTIME_EVALUATED_ANNOTATION` and
`RUNTIME_REQUIRED_ANNOTATION`. If an annotation is runtime-evaluated and
not runtime-required, and
we didn't already bail out at the
`semantic.execution_context().is_runtime()` check earlier in the
same function, then we know that we're in an annotation that _would_
have been typing-only on 3.14+.

Test Plan
--

New mdtests and the ecosystem check here. I expect -12 scikit-build-core
diagnostics compared to main.
@ntBre
ntBre merged commit 5fe6903 into brent/0.17.0 Sep 25, 2026
51 checks passed
@ntBre
ntBre deleted the brent/stabilize-tid255 branch September 25, 2026 13:23
ntBre added a commit that referenced this pull request Sep 25, 2026
ntBre added a commit that referenced this pull request Sep 25, 2026
ntBre added a commit that referenced this pull request Oct 1, 2026
ntBre added a commit that referenced this pull request Oct 1, 2026
ntBre added a commit that referenced this pull request Oct 9, 2026
ntBre added a commit that referenced this pull request Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant