---
source: crates/ruff_linter/src/rules/flake8_use_pathlib/mod.rs
---
PTH100 [*] `os.path.abspath()` should be replaced by `Path.resolve()`
  --> import_from_as.py:14:5
   |
12 | q = "bar"
13 |
14 | a = xabspath(p)
   |     ^^^^^^^^
15 | aa = xchmod(p)
16 | aaa = xmkdir(p)
   |
help: Replace with `Path(...).resolve()`
   |
9  | from os.path import samefile as xsamefile, splitext as xsplitext
10 + import pathlib
11 |
12 | p = "/foo"
13 | q = "bar"
14 |
   - a = xabspath(p)
15 + a = pathlib.Path(p).resolve()
16 | aa = xchmod(p)
   |
note: This is an unsafe fix and may change runtime behavior

PTH101 `os.chmod()` should be replaced by `Path.chmod()`
  --> import_from_as.py:15:6
   |
14 | a = xabspath(p)
15 | aa = xchmod(p)
   |      ^^^^^^
16 | aaa = xmkdir(p)
17 | xmakedirs(p)
   |
help: Replace with `Path(...).chmod(...)`

PTH102 [*] `os.mkdir()` should be replaced by `Path.mkdir()`
  --> import_from_as.py:16:7
   |
14 | a = xabspath(p)
15 | aa = xchmod(p)
16 | aaa = xmkdir(p)
   |       ^^^^^^
17 | xmakedirs(p)
18 | xrename(p)
   |
help: Replace with `Path(...).mkdir()`
   |
9  | from os.path import samefile as xsamefile, splitext as xsplitext
10 + import pathlib
11 |
--------------------------------------------------------------------------------
16 | aa = xchmod(p)
   - aaa = xmkdir(p)
17 + aaa = pathlib.Path(p).mkdir()
18 | xmakedirs(p)
   |

PTH103 [*] `os.makedirs()` should be replaced by `Path.mkdir(parents=True)`
  --> import_from_as.py:17:1
   |
15 | aa = xchmod(p)
16 | aaa = xmkdir(p)
17 | xmakedirs(p)
   | ^^^^^^^^^
18 | xrename(p)
19 | xreplace(p)
   |
help: Replace with `Path(...).mkdir(parents=True)`
   |
9  | from os.path import samefile as xsamefile, splitext as xsplitext
10 + import pathlib
11 |
--------------------------------------------------------------------------------
17 | aaa = xmkdir(p)
   - xmakedirs(p)
18 + pathlib.Path(p).mkdir(parents=True)
19 | xrename(p)
   |

PTH104 `os.rename()` should be replaced by `Path.rename()`
  --> import_from_as.py:18:1
   |
16 | aaa = xmkdir(p)
17 | xmakedirs(p)
18 | xrename(p)
   | ^^^^^^^
19 | xreplace(p)
20 | xrmdir(p)
   |
help: Replace with `Path(...).rename(...)`

PTH105 `os.replace()` should be replaced by `Path.replace()`
  --> import_from_as.py:19:1
   |
17 | xmakedirs(p)
18 | xrename(p)
19 | xreplace(p)
   | ^^^^^^^^
20 | xrmdir(p)
21 | xremove(p)
   |
help: Replace with `Path(...).replace(...)`

PTH106 [*] `os.rmdir()` should be replaced by `Path.rmdir()`
  --> import_from_as.py:20:1
   |
18 | xrename(p)
19 | xreplace(p)
20 | xrmdir(p)
   | ^^^^^^
21 | xremove(p)
22 | xunlink(p)
   |
help: Replace with `Path(...).rmdir()`
   |
9  | from os.path import samefile as xsamefile, splitext as xsplitext
10 + import pathlib
11 |
--------------------------------------------------------------------------------
20 | xreplace(p)
   - xrmdir(p)
21 + pathlib.Path(p).rmdir()
22 | xremove(p)
   |

PTH107 [*] `os.remove()` should be replaced by `Path.unlink()`
  --> import_from_as.py:21:1
   |
19 | xreplace(p)
20 | xrmdir(p)
21 | xremove(p)
   | ^^^^^^^
22 | xunlink(p)
23 | xgetcwd(p)
   |
help: Replace with `Path(...).unlink()`
   |
9  | from os.path import samefile as xsamefile, splitext as xsplitext
10 + import pathlib
11 |
--------------------------------------------------------------------------------
21 | xrmdir(p)
   - xremove(p)
22 + pathlib.Path(p).unlink()
23 | xunlink(p)
   |

PTH108 [*] `os.unlink()` should be replaced by `Path.unlink()`
  --> import_from_as.py:22:1
   |
20 | xrmdir(p)
21 | xremove(p)
22 | xunlink(p)
   | ^^^^^^^
23 | xgetcwd(p)
24 | b = xexists(p)
   |
help: Replace with `Path(...).unlink()`
   |
9  | from os.path import samefile as xsamefile, splitext as xsplitext
10 + import pathlib
11 |
--------------------------------------------------------------------------------
22 | xremove(p)
   - xunlink(p)
23 + pathlib.Path(p).unlink()
24 | xgetcwd(p)
   |

PTH109 `os.getcwd()` should be replaced by `Path.cwd()`
  --> import_from_as.py:23:1
   |
21 | xremove(p)
22 | xunlink(p)
23 | xgetcwd(p)
   | ^^^^^^^
24 | b = xexists(p)
25 | bb = xexpanduser(p)
   |
help: Replace with `Path.cwd()`

PTH110 [*] `os.path.exists()` should be replaced by `Path.exists()`
  --> import_from_as.py:24:5
   |
22 | xunlink(p)
23 | xgetcwd(p)
24 | b = xexists(p)
   |     ^^^^^^^
25 | bb = xexpanduser(p)
26 | bbb = xisdir(p)
   |
help: Replace with `Path(...).exists()`
   |
9  | from os.path import samefile as xsamefile, splitext as xsplitext
10 + import pathlib
11 |
--------------------------------------------------------------------------------
24 | xgetcwd(p)
   - b = xexists(p)
25 + b = pathlib.Path(p).exists()
26 | bb = xexpanduser(p)
   |

PTH111 [*] `os.path.expanduser()` should be replaced by `Path.expanduser()`
  --> import_from_as.py:25:6
   |
23 | xgetcwd(p)
24 | b = xexists(p)
25 | bb = xexpanduser(p)
   |      ^^^^^^^^^^^
26 | bbb = xisdir(p)
27 | bbbb = xisfile(p)
   |
help: Replace with `Path(...).expanduser()`
   |
9  | from os.path import samefile as xsamefile, splitext as xsplitext
10 + import pathlib
11 |
--------------------------------------------------------------------------------
25 | b = xexists(p)
   - bb = xexpanduser(p)
26 + bb = pathlib.Path(p).expanduser()
27 | bbb = xisdir(p)
   |
note: This is an unsafe fix and may change runtime behavior

PTH112 [*] `os.path.isdir()` should be replaced by `Path.is_dir()`
  --> import_from_as.py:26:7
   |
24 | b = xexists(p)
25 | bb = xexpanduser(p)
26 | bbb = xisdir(p)
   |       ^^^^^^
27 | bbbb = xisfile(p)
28 | bbbbb = xislink(p)
   |
help: Replace with `Path(...).is_dir()`
   |
9  | from os.path import samefile as xsamefile, splitext as xsplitext
10 + import pathlib
11 |
--------------------------------------------------------------------------------
26 | bb = xexpanduser(p)
   - bbb = xisdir(p)
27 + bbb = pathlib.Path(p).is_dir()
28 | bbbb = xisfile(p)
   |

PTH113 [*] `os.path.isfile()` should be replaced by `Path.is_file()`
  --> import_from_as.py:27:8
   |
25 | bb = xexpanduser(p)
26 | bbb = xisdir(p)
27 | bbbb = xisfile(p)
   |        ^^^^^^^
28 | bbbbb = xislink(p)
29 | xreadlink(p)
   |
help: Replace with `Path(...).is_file()`
   |
9  | from os.path import samefile as xsamefile, splitext as xsplitext
10 + import pathlib
11 |
--------------------------------------------------------------------------------
27 | bbb = xisdir(p)
   - bbbb = xisfile(p)
28 + bbbb = pathlib.Path(p).is_file()
29 | bbbbb = xislink(p)
   |

PTH114 [*] `os.path.islink()` should be replaced by `Path.is_symlink()`
  --> import_from_as.py:28:9
   |
26 | bbb = xisdir(p)
27 | bbbb = xisfile(p)
28 | bbbbb = xislink(p)
   |         ^^^^^^^
29 | xreadlink(p)
30 | xstat(p)
   |
help: Replace with `Path(...).is_symlink()`
   |
9  | from os.path import samefile as xsamefile, splitext as xsplitext
10 + import pathlib
11 |
--------------------------------------------------------------------------------
28 | bbbb = xisfile(p)
   - bbbbb = xislink(p)
29 + bbbbb = pathlib.Path(p).is_symlink()
30 | xreadlink(p)
   |

PTH115 [*] `os.readlink()` should be replaced by `Path.readlink()`
  --> import_from_as.py:29:1
   |
27 | bbbb = xisfile(p)
28 | bbbbb = xislink(p)
29 | xreadlink(p)
   | ^^^^^^^^^
30 | xstat(p)
31 | xisabs(p)
   |
help: Replace with `Path(...).readlink()`
   |
9  | from os.path import samefile as xsamefile, splitext as xsplitext
10 + import pathlib
11 |
--------------------------------------------------------------------------------
29 | bbbbb = xislink(p)
   - xreadlink(p)
30 + pathlib.Path(p).readlink()
31 | xstat(p)
   |

PTH116 `os.stat()` should be replaced by `Path.stat()`, `Path.owner()`, or `Path.group()`
  --> import_from_as.py:30:1
   |
28 | bbbbb = xislink(p)
29 | xreadlink(p)
30 | xstat(p)
   | ^^^^^
31 | xisabs(p)
32 | xjoin(p, q)
   |

PTH117 [*] `os.path.isabs()` should be replaced by `Path.is_absolute()`
  --> import_from_as.py:31:1
   |
29 | xreadlink(p)
30 | xstat(p)
31 | xisabs(p)
   | ^^^^^^
32 | xjoin(p, q)
33 | s.join((p, q))
   |
help: Replace with `Path(...).is_absolute()`
   |
9  | from os.path import samefile as xsamefile, splitext as xsplitext
10 + import pathlib
11 |
--------------------------------------------------------------------------------
31 | xstat(p)
   - xisabs(p)
32 + pathlib.Path(p).is_absolute()
33 | xjoin(p, q)
   |

PTH118 `os.path.join()` should be replaced by `Path` with `/` operator
  --> import_from_as.py:32:1
   |
30 | xstat(p)
31 | xisabs(p)
32 | xjoin(p, q)
   | ^^^^^
33 | s.join((p, q))
34 | s.join([p, q])
   |

PTH118 `os.sep.join()` should be replaced by `Path` with `/` operator
  --> import_from_as.py:33:1
   |
31 | xisabs(p)
32 | xjoin(p, q)
33 | s.join((p, q))
   | ^^^^^^
34 | s.join([p, q])
35 | xbasename(p)
   |

PTH118 `os.sep.join()` should be replaced by `Path` with `/` operator
  --> import_from_as.py:34:1
   |
32 | xjoin(p, q)
33 | s.join((p, q))
34 | s.join([p, q])
   | ^^^^^^
35 | xbasename(p)
36 | xdirname(p)
   |

PTH119 [*] `os.path.basename()` should be replaced by `Path.name`
  --> import_from_as.py:35:1
   |
33 | s.join((p, q))
34 | s.join([p, q])
35 | xbasename(p)
   | ^^^^^^^^^
36 | xdirname(p)
37 | xsamefile(p)
   |
help: Replace with `Path(...).name`
   |
9  | from os.path import samefile as xsamefile, splitext as xsplitext
10 + import pathlib
11 |
--------------------------------------------------------------------------------
35 | s.join([p, q])
   - xbasename(p)
36 + pathlib.Path(p).name
37 | xdirname(p)
   |
note: This is an unsafe fix and may change runtime behavior

PTH120 [*] `os.path.dirname()` should be replaced by `Path.parent`
  --> import_from_as.py:36:1
   |
34 | s.join([p, q])
35 | xbasename(p)
36 | xdirname(p)
   | ^^^^^^^^
37 | xsamefile(p)
38 | xsplitext(p)
   |
help: Replace with `Path(...).parent`
   |
9  | from os.path import samefile as xsamefile, splitext as xsplitext
10 + import pathlib
11 |
--------------------------------------------------------------------------------
36 | xbasename(p)
   - xdirname(p)
37 + pathlib.Path(p).parent
38 | xsamefile(p)
   |
note: This is an unsafe fix and may change runtime behavior

PTH121 `os.path.samefile()` should be replaced by `Path.samefile()`
  --> import_from_as.py:37:1
   |
35 | xbasename(p)
36 | xdirname(p)
37 | xsamefile(p)
   | ^^^^^^^^^
38 | xsplitext(p)
   |
help: Replace with `Path(...).samefile()`

PTH122 `os.path.splitext()` should be replaced by `Path.suffix`, `Path.stem`, and `Path.parent`
  --> import_from_as.py:38:1
   |
36 | xdirname(p)
37 | xsamefile(p)
38 | xsplitext(p)
   | ^^^^^^^^^
   |
