Skip to content

[flake8-tidy-imports] Skip lazy-import-mismatch in stubs (TID254) - #29095

Merged
ntBre merged 2 commits into
astral-sh:mainfrom
nekomario28:fix-tid254-stubs
Oct 6, 2026
Merged

ntBre merged 2 commits into
astral-sh:mainfrom
nekomario28:fix-tid254-stubs

Conversation

@nekomario28

@nekomario28 nekomario28 commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #29070.

TID254 incorrectly flags eager imports in stub files when require-lazy is configured. Skip the rule for stubs.

Test Plan

Added a pyi block covering require-lazy and ban-lazy for both import and from ... import. The lazy-import-mismatch mdtest passes.

@astral-sh-bot
astral-sh-bot Bot requested a review from ntBre October 4, 2026 14:14

@ntBre ntBre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks right to me. I just had a suggestion about the tests.

}

#[test]
fn preview_lazy_import_mismatch_stub() -> Result<()> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use mdtests for this:

ruff/CONTRIBUTING.md

Lines 233 to 240 in bd2d6f6

#### Rule testing: fixtures and snapshots
To test rules, Ruff uses the mdtest framework, initially developed for ty. Mdtests are written as
Markdown files with Python code and TOML configuration blocks alongside prose
descriptions. Generally, there will be one directory per linter (e.g. `flake8-bandit` for the `S`
rules) with nested files for each rule (e.g. `unsafe-markup-use.md` for `S704`). Within these
files, you can define additional Markdown sections to group related tests and their settings
together.

You should be able to use a pyi block in the existing mdtest file and avoid needing this setup function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Moved the stub tests into a pyi block in the existing mdtest.

@ntBre ntBre added the bug An issue describing something that isn't working, or a PR that fixes a bug label Oct 5, 2026
@astral-sh-bot

astral-sh-bot Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

βœ… ecosystem check detected no linter changes.

Linter (preview)

βœ… ecosystem check detected no linter changes.

@ntBre ntBre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ntBre
ntBre enabled auto-merge (squash) October 6, 2026 13:42
@ntBre
ntBre merged commit 6a50305 into astral-sh:main Oct 6, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug An issue describing something that isn't working, or a PR that fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lazy-import-mismatch - false positive in stubs

2 participants