Skip to content

Commit

Permalink
Raise PTH201 for Path("") (#6095)
Browse files Browse the repository at this point in the history
  • Loading branch information
harupy committed Jul 26, 2023
1 parent 77396c6 commit 9912724
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
_ = Path(".")
_ = pth(".")
_ = PurePath(".")
_ = Path("")

# no match
_ = Path()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,11 @@ pub(crate) fn path_constructor_current_directory(checker: &mut Checker, expr: &E
return;
};

if value != "." {
return;
}

let mut diagnostic = Diagnostic::new(PathConstructorCurrentDirectory, *range);
if checker.patch(diagnostic.kind.rule()) {
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(*range)));
if matches!(value.as_str(), "" | ".") {
let mut diagnostic = Diagnostic::new(PathConstructorCurrentDirectory, *range);
if checker.patch(diagnostic.kind.rule()) {
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(*range)));
}
checker.diagnostics.push(diagnostic);
}
checker.diagnostics.push(diagnostic);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ PTH201.py:5:10: PTH201 [*] Do not pass the current directory explicitly to `Path
5 |+_ = Path()
6 6 | _ = pth(".")
7 7 | _ = PurePath(".")
8 8 |
8 8 | _ = Path("")

PTH201.py:6:9: PTH201 [*] Do not pass the current directory explicitly to `Path`
|
Expand All @@ -28,6 +28,7 @@ PTH201.py:6:9: PTH201 [*] Do not pass the current directory explicitly to `Path`
6 | _ = pth(".")
| ^^^ PTH201
7 | _ = PurePath(".")
8 | _ = Path("")
|
= help: Remove the current directory argument

Expand All @@ -38,17 +39,16 @@ PTH201.py:6:9: PTH201 [*] Do not pass the current directory explicitly to `Path`
6 |-_ = pth(".")
6 |+_ = pth()
7 7 | _ = PurePath(".")
8 8 |
9 9 | # no match
8 8 | _ = Path("")
9 9 |

PTH201.py:7:14: PTH201 [*] Do not pass the current directory explicitly to `Path`
|
5 | _ = Path(".")
6 | _ = pth(".")
7 | _ = PurePath(".")
| ^^^ PTH201
8 |
9 | # no match
8 | _ = Path("")
|
= help: Remove the current directory argument

Expand All @@ -58,8 +58,29 @@ PTH201.py:7:14: PTH201 [*] Do not pass the current directory explicitly to `Path
6 6 | _ = pth(".")
7 |-_ = PurePath(".")
7 |+_ = PurePath()
8 8 |
9 9 | # no match
10 10 | _ = Path()
8 8 | _ = Path("")
9 9 |
10 10 | # no match

PTH201.py:8:10: PTH201 [*] Do not pass the current directory explicitly to `Path`
|
6 | _ = pth(".")
7 | _ = PurePath(".")
8 | _ = Path("")
| ^^ PTH201
9 |
10 | # no match
|
= help: Remove the current directory argument

Fix
5 5 | _ = Path(".")
6 6 | _ = pth(".")
7 7 | _ = PurePath(".")
8 |-_ = Path("")
8 |+_ = Path()
9 9 |
10 10 | # no match
11 11 | _ = Path()


0 comments on commit 9912724

Please sign in to comment.