-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flake8-use-pathlib
] Recommend Path.iterdir()
over os.listdir()
(PTH208
)
#14509
base: main
Are you sure you want to change the base?
Conversation
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PTH208 | 52 | 52 | 0 | 0 | 0 |
I noticed two common patterns when reviewing the ecosystem checks:
The first requires using The second mainly becomes more verbose. I'm interested in more opinions if we should exclude them. Wdyt @sbrugman https://github.com/bokeh/bokeh/blob/829b2a75c402d0d0abd7e37ff201fbdfd949d857/examples/server/app/simple_hdf5/main.py#L19 |
To be pedantic, |
The pathlib rules should flag all It could be good to already include these cases in the tests to make sure they are covered when autofix is implemented later. The complexity here is in the fix, not in the detection of the violation. Going over the ecosystem results I realise that Using 'demo_data.hdf5' not in os.listdir(app_dir) Idiomatic not os.path.exists(os.path.join(app_dir), 'demo_data.hdf5') Pathlib equivalent: not (app_dir / "demo_data.hdf5").exists() Checking if a directory is empty with not os.listdir(api_dir) Users should probably write something like: next(os.scandir(api_dir), None) is None Pathlib equivalent: next(api_dir.iterdir(), None) is None |
Summary
Resolves #14490.
Test Plan
cargo nextest run
andcargo insta test
.