Skip to content

Commit b34e964

Browse files
committed
Cleaning up stringify_path
1 parent c879415 commit b34e964

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

pandas/io/common.py

+2-14
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from io import BufferedIOBase, BytesIO, RawIOBase, TextIOWrapper
88
import mmap
99
import os
10-
from os import PathLike
1110
from typing import IO, Any, AnyStr, Dict, List, Mapping, Optional, Tuple, cast
1211
from urllib.parse import (
1312
urljoin,
@@ -176,19 +175,8 @@ def stringify_path(
176175
Any other object is passed through unchanged, which includes bytes,
177176
strings, buffers, or anything else that's not even path-like.
178177
"""
179-
if hasattr(filepath_or_buffer, "__fspath__"):
180-
# https://github.com/python/mypy/issues/1424
181-
# error: Item "str" of "Union[str, Path, IO[str]]" has no attribute
182-
# "__fspath__" [union-attr]
183-
# error: Item "IO[str]" of "Union[str, Path, IO[str]]" has no attribute
184-
# "__fspath__" [union-attr]
185-
# error: Item "str" of "Union[str, Path, IO[bytes]]" has no attribute
186-
# "__fspath__" [union-attr]
187-
# error: Item "IO[bytes]" of "Union[str, Path, IO[bytes]]" has no
188-
# attribute "__fspath__" [union-attr]
189-
filepath_or_buffer = filepath_or_buffer.__fspath__() # type: ignore[union-attr]
190-
elif isinstance(filepath_or_buffer, PathLike):
191-
filepath_or_buffer = str(filepath_or_buffer)
178+
if isinstance(filepath_or_buffer, os.PathLike):
179+
filepath_or_buffer = filepath_or_buffer.__fspath__()
192180
return _expand_user(filepath_or_buffer)
193181

194182

0 commit comments

Comments
 (0)