Skip to content

[flake8-use-pathlib] Add display-only fix for os.listdir (PTH208) - #28027

Merged
ntBre merged 4 commits into
astral-sh:mainfrom
fly1d:codex/pth208-display-only
Aug 28, 2026
Merged

ntBre merged 4 commits into
astral-sh:mainfrom
fly1d:codex/pth208-display-only

Conversation

@fly1d

@fly1d fly1d commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a display-only suggestion for PTH208 diagnostics with a path argument:

Path(path).iterdir()

The suggestion is intentionally not an automatic fix because os.listdir returns strings or bytes, while Path.iterdir() returns Path objects and can change downstream behavior. The existing diagnostic remains unchanged, and file-descriptor calls do not receive the suggestion.

Part of #2331.

Verification

  • INSTA_FORCE_PASS=1 INSTA_UPDATE=always cargo test -p ruff_linter flake8_use_pathlib::tests --lib (34 passed)
  • cargo fmt --all -- --check
  • git diff --check

OpenAI Codex assisted with implementation and verification. The contributor reviewed the change before submission.

@astral-sh-bot
astral-sh-bot Bot requested a review from ntBre August 25, 2026 05:58
OpenAI Codex assisted with implementation and verification. The contributor reviewed the change before submission.
@fly1d
fly1d force-pushed the codex/pth208-display-only branch from 9882e6d to 39b40ac Compare August 25, 2026 05:59
@ntBre ntBre added the bot:ai-policy-close Auto-close a PR due to a violation of the org AI policy label Aug 25, 2026
@astral-sh-bot

astral-sh-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown

We support using AI (i.e., LLMs) while coding. However, AI should not be used to communicate with maintainers.

Please read and follow our AI policy when submitting issues and pull requests.

@astral-sh-bot astral-sh-bot Bot closed this Aug 25, 2026
@fly1d

fly1d commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

I confirm that I have read the AI policy. However, as a non-native English speaker, I may not have fully understood all the details. Please note that the comments were originally written by me, with AI used solely for language polishing.

@ntBre

ntBre commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Your test plan specifically read as very LLM-generated to me, but I'll take you at your word and reopen this. Thank you for reading the policy.

@ntBre ntBre reopened this Aug 26, 2026
@ntBre ntBre removed the bot:ai-policy-close Auto-close a PR due to a violation of the org AI policy label Aug 26, 2026

@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 reasonable at a high level, but we still need to check that the diagnostic is enabled and also use the importer infrastructure to ensure that Path is in scope for the fix. I also had a couple of smaller suggestions.

@ntBre ntBre added the fixes Related to suggested fixes for violations label Aug 26, 2026
@ntBre

ntBre commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

As one other note, I think we've mosty added pathlib fixes in preview, but that's only required for safe fixes by our versioning policy. I think this display-only fix is fine to add in stable.

@fly1d
fly1d force-pushed the codex/pth208-display-only branch 2 times, most recently from 4f4b004 to 39b40ac Compare August 27, 2026 02:56
fly1d and others added 3 commits August 27, 2026 11:16
Use the diagnostic-enabled reporting path and the importer when suggesting a pathlib replacement for os.listdir. Add a dedicated fix title and update the snapshot.

OpenAI Codex assisted with implementation and verification. I reviewed the changes before submission.

@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 good to me. I fixed the merge conflicts and then resolved the () return thing. Returning None wasn't quite what I had in mind, but it wasn't quite as quick a fix as adding semicolons like I hoped.

@ntBre ntBre changed the title fix(PTH208): add display-only hint for os.listdir [flake8-use-pathlib] Add display-only fix for os.listdir (PTH208) Aug 28, 2026
@astral-sh-bot

astral-sh-bot Bot commented Aug 28, 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 merged commit 4f0b918 into astral-sh:main Aug 28, 2026
48 checks passed
ntBre added a commit that referenced this pull request Aug 28, 2026
Summary
--

Noticed this while reviewing #28027.

Test Plan
--

Existing tests
ntBre added a commit that referenced this pull request Aug 28, 2026
Summary
--

Noticed this while reviewing #28027.

Test Plan
--

Existing tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixes Related to suggested fixes for violations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants