Skip to content

Commit

Permalink
[flake8-use-pathlib] extend PTH118 with os.sep (#5935)
Browse files Browse the repository at this point in the history
Closes #5905

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
  • Loading branch information
sbrugman and charliermarsh authored Jul 21, 2023
1 parent d62183b commit f7b1565
Show file tree
Hide file tree
Showing 10 changed files with 688 additions and 582 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os.path

p = "/foo"
q = "bar"

a = os.path.abspath(p)
aa = os.chmod(p)
Expand All @@ -21,7 +22,9 @@
os.readlink(p)
os.stat(p)
os.path.isabs(p)
os.path.join(p)
os.path.join(p, q)
os.sep.join([p, q])
os.sep.join((p, q))
os.path.basename(p)
os.path.dirname(p)
os.path.samefile(p)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os.path as foo_p

p = "/foo"
q = "bar"

a = foo_p.abspath(p)
aa = foo.chmod(p)
Expand All @@ -21,7 +22,9 @@
foo.readlink(p)
foo.stat(p)
foo_p.isabs(p)
foo_p.join(p)
foo_p.join(p, q)
foo.sep.join([p, q])
foo.sep.join((p, q))
foo_p.basename(p)
foo_p.dirname(p)
foo_p.samefile(p)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from os import chmod, mkdir, makedirs, rename, replace, rmdir
from os import chmod, mkdir, makedirs, rename, replace, rmdir, sep
from os import remove, unlink, getcwd, readlink, stat
from os.path import abspath, exists, expanduser, isdir, isfile, islink
from os.path import isabs, join, basename, dirname, samefile, splitext

p = "/foo"
q = "bar"

a = abspath(p)
aa = chmod(p)
Expand All @@ -23,7 +24,9 @@
readlink(p)
stat(p)
isabs(p)
join(p)
join(p, q)
sep.join((p, q))
sep.join([p, q])
basename(p)
dirname(p)
samefile(p)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from os import chmod as xchmod, mkdir as xmkdir
from os import chmod as xchmod, mkdir as xmkdir, sep as s
from os import makedirs as xmakedirs, rename as xrename, replace as xreplace
from os import rmdir as xrmdir, remove as xremove, unlink as xunlink
from os import getcwd as xgetcwd, readlink as xreadlink, stat as xstat
Expand All @@ -9,6 +9,7 @@
from os.path import samefile as xsamefile, splitext as xsplitext

p = "/foo"
q = "bar"

a = xabspath(p)
aa = xchmod(p)
Expand All @@ -28,7 +29,9 @@
xreadlink(p)
xstat(p)
xisabs(p)
xjoin(p)
xjoin(p, q)
s.join((p, q))
s.join([p, q])
xbasename(p)
xdirname(p)
xsamefile(p)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,18 @@ pub(crate) fn replaceable_by_pathlib(checker: &mut Checker, expr: &Expr) {
// PTH117
["os", "path", "isabs"] => Some(OsPathIsabs.into()),
// PTH118
["os", "path", "join"] => Some(OsPathJoin.into()),
["os", "path", "join"] => Some(
OsPathJoin {
module: "path".to_string(),
}
.into(),
),
["os", "sep", "join"] => Some(
OsPathJoin {
module: "sep".to_string(),
}
.into(),
),
// PTH119
["os", "path", "basename"] => Some(OsPathBasename.into()),
// PTH120
Expand Down
Loading

0 comments on commit f7b1565

Please sign in to comment.