Skip to content

Commit 91d4cc5

Browse files
committed
Use os.fspath instead of __fspath__ for reading paths
1 parent 59c3c80 commit 91d4cc5

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

git/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ def read(self) -> None: # type: ignore[override]
634634
self._read(file_path, file_path.name)
635635
else:
636636
# Assume a path if it is not a file-object.
637-
file_path = cast(PathLike, file_path)
637+
file_path = os.fspath(file_path)
638638
try:
639639
with open(file_path, "rb") as fp:
640640
file_ok = True

git/repo/base.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,9 @@ def __init__(
219219
# Given how the tests are written, this seems more likely to catch Cygwin
220220
# git used from Windows than Windows git used from Cygwin. Therefore
221221
# changing to Cygwin-style paths is the relevant operation.
222-
epath = cygpath(epath if isinstance(epath, str) else epath.__fspath__())
222+
epath = cygpath(os.fspath(epath))
223223

224-
epath = epath or path or os.getcwd()
225-
if not isinstance(epath, str):
226-
epath = epath.__fspath__()
224+
epath = os.fspath(epath)
227225
if expand_vars and re.search(self.re_envvars, epath):
228226
warnings.warn(
229227
"The use of environment variables in paths is deprecated"
@@ -1361,11 +1359,8 @@ def _clone(
13611359
) -> "Repo":
13621360
odbt = kwargs.pop("odbt", odb_default_type)
13631361

1364-
# When pathlib.Path or other class-based path is passed
1365-
if not isinstance(url, str):
1366-
url = url.__fspath__()
1367-
if not isinstance(path, str):
1368-
path = path.__fspath__()
1362+
url = os.fspath(url)
1363+
path = os.fspath(path)
13691364

13701365
## A bug win cygwin's Git, when `--bare` or `--separate-git-dir`
13711366
# it prepends the cwd or(?) the `url` into the `path, so::

0 commit comments

Comments
 (0)