Repository navigation
[flake8-use-pathlib] Add display-only fix for os.listdir (PTH208) - #28027
Conversation
OpenAI Codex assisted with implementation and verification. The contributor reviewed the change before submission.
9882e6d to
39b40ac
Compare
|
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. |
|
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. |
|
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
left a comment
There was a problem hiding this comment.
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.
|
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. |
4f4b004 to
39b40ac
Compare
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
left a comment
There was a problem hiding this comment.
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.
flake8-use-pathlib] Add display-only fix for os.listdir (PTH208)
|
Summary -- Noticed this while reviewing #28027. Test Plan -- Existing tests
Summary
Adds a display-only suggestion for
PTH208diagnostics with a path argument:The suggestion is intentionally not an automatic fix because
os.listdirreturns strings or bytes, whilePath.iterdir()returnsPathobjects 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 -- --checkgit diff --check