Skip to content

Conversation

@Kalmaegi
Copy link
Contributor

@Kalmaegi Kalmaegi commented Apr 29, 2025

Summary

Fixes: #17695

@github-actions
Copy link
Contributor

github-actions bot commented Apr 29, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Member

@dhruvmanila dhruvmanila left a comment

Choose a reason for hiding this comment

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

Thanks for looking into it. Can you please add soe test cases when os.listdir is being used with file descriptors? We should also make sure to support both positional and keyword arguments, so both os.listdir('/tmp') and os.listdir(path='/tmp') are considered and tested.

@dhruvmanila dhruvmanila added the bug Something isn't working label Apr 29, 2025
Copy link
Member

@dhruvmanila dhruvmanila left a comment

Choose a reason for hiding this comment

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

Thank you!

I think you forgot to update the snapshots which caused the CI failure. I moved the test cases at the end of the file to avoid needing to update the snapshots as this shouldn't raise any diagnostics.

I also took this moment to refactor the code in replaceable_by_pathlib to use let ... else ... instead of the long if let ... code, specifically by separating the resolve_qualified_name call and the match against the qualified name. I also update the diagnostic_kind conversion to avoid using Option and use early return instead.

@dhruvmanila dhruvmanila changed the title [flake8-use-pathlib] do not suggest Path.iterdir() for os.listdir with file descriptor [flake8-use-pathlib] Avoid suggesting Path.iterdir() for os.listdir with file descriptor (PTH208) Apr 30, 2025
@Kalmaegi
Copy link
Contributor Author

Thank you!

I think you forgot to update the snapshots which caused the CI failure. I moved the test cases at the end of the file to avoid needing to update the snapshots as this shouldn't raise any diagnostics.

I also took this moment to refactor the code in replaceable_by_pathlib to use let ... else ... instead of the long if let ... code, specifically by separating the resolve_qualified_name call and the match against the qualified name. I also update the diagnostic_kind conversion to avoid using Option and use early return instead.

Thank you very much for your help! —I’m also learning a lot from this experience.

@dhruvmanila dhruvmanila merged commit 0e85cbd into astral-sh:main Apr 30, 2025
33 checks passed
dcreager added a commit that referenced this pull request May 1, 2025
* main:
  [red-knot] Preliminary `NamedTuple` support (#17738)
  [red-knot] Add tests for classes that have incompatible `__new__` and `__init__` methods (#17747)
  Update dependency vite to v6.2.7 (#17746)
  [red-knot] Update call binding to return all matching overloads (#17618)
  [`airflow`] apply Replacement::AutoImport to `AIR312` (#17570)
  [`ruff`] Add fix safety section (`RUF028`) (#17722)
  [syntax-errors] Detect single starred expression assignment `x = *y` (#17624)
  py-fuzzer: fix minimization logic when `--only-new-bugs` is passed (#17739)
  Fix example syntax for pydocstyle ignore_var_parameters option (#17740)
  [red-knot] Update salsa to prevent panic in custom panic-handler (#17742)
  [red-knot] Ban direct instantiation of generic protocols as well as non-generic ones (#17741)
  [red-knot] Lookup of `__new__` (#17733)
  [red-knot] Check decorator consistency on overloads (#17684)
  [`flake8-use-pathlib`] Avoid suggesting `Path.iterdir()` for `os.listdir` with file descriptor (`PTH208`) (#17715)
  [red-knot] Check overloads without an implementation (#17681)
  Expand Semantic Syntax Coverage (#17725)
  [red-knot] Check for invalid overload usages (#17609)
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.

PTH208 suggests Path.iterdir(), which does not support file descriptors

2 participants