-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[
flake8-use-pathlib
] Recommend Path.iterdir()
over os.listdir()
…
… (`PTH208`) (#14509) Co-authored-by: Micha Reiser <[email protected]>
- Loading branch information
1 parent
14ba469
commit 187974e
Showing
8 changed files
with
138 additions
and
4 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
crates/ruff_linter/resources/test/fixtures/flake8_use_pathlib/PTH208.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import os | ||
|
||
os.listdir('.') | ||
os.listdir(b'.') | ||
|
||
string_path = '.' | ||
os.listdir(string_path) | ||
|
||
bytes_path = b'.' | ||
os.listdir(bytes_path) | ||
|
||
|
||
from pathlib import Path | ||
|
||
path_path = Path('.') | ||
os.listdir(path_path) | ||
|
||
|
||
if os.listdir("dir"): | ||
... | ||
|
||
if "file" in os.listdir("dir"): | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...se_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__PTH208_PTH208.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_use_pathlib/mod.rs | ||
snapshot_kind: text | ||
--- | ||
PTH208.py:3:1: PTH208 Use `pathlib.Path.iterdir()` instead. | ||
| | ||
1 | import os | ||
2 | | ||
3 | os.listdir('.') | ||
| ^^^^^^^^^^ PTH208 | ||
4 | os.listdir(b'.') | ||
| | ||
|
||
PTH208.py:4:1: PTH208 Use `pathlib.Path.iterdir()` instead. | ||
| | ||
3 | os.listdir('.') | ||
4 | os.listdir(b'.') | ||
| ^^^^^^^^^^ PTH208 | ||
5 | | ||
6 | string_path = '.' | ||
| | ||
|
||
PTH208.py:7:1: PTH208 Use `pathlib.Path.iterdir()` instead. | ||
| | ||
6 | string_path = '.' | ||
7 | os.listdir(string_path) | ||
| ^^^^^^^^^^ PTH208 | ||
8 | | ||
9 | bytes_path = b'.' | ||
| | ||
|
||
PTH208.py:10:1: PTH208 Use `pathlib.Path.iterdir()` instead. | ||
| | ||
9 | bytes_path = b'.' | ||
10 | os.listdir(bytes_path) | ||
| ^^^^^^^^^^ PTH208 | ||
| | ||
|
||
PTH208.py:16:1: PTH208 Use `pathlib.Path.iterdir()` instead. | ||
| | ||
15 | path_path = Path('.') | ||
16 | os.listdir(path_path) | ||
| ^^^^^^^^^^ PTH208 | ||
| | ||
|
||
PTH208.py:19:4: PTH208 Use `pathlib.Path.iterdir()` instead. | ||
| | ||
19 | if os.listdir("dir"): | ||
| ^^^^^^^^^^ PTH208 | ||
20 | ... | ||
| | ||
|
||
PTH208.py:22:14: PTH208 Use `pathlib.Path.iterdir()` instead. | ||
| | ||
20 | ... | ||
21 | | ||
22 | if "file" in os.listdir("dir"): | ||
| ^^^^^^^^^^ PTH208 | ||
23 | ... | ||
| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.