|  | 
| 7 | 7 | from io import BufferedIOBase, BytesIO, RawIOBase, TextIOWrapper | 
| 8 | 8 | import mmap | 
| 9 | 9 | import os | 
| 10 |  | -import pathlib | 
| 11 | 10 | from typing import IO, Any, AnyStr, Dict, List, Mapping, Optional, Tuple, cast | 
| 12 | 11 | from urllib.parse import ( | 
| 13 | 12 |  urljoin, | 
| @@ -176,19 +175,8 @@ def stringify_path( | 
| 176 | 175 |  Any other object is passed through unchanged, which includes bytes, | 
| 177 | 176 |  strings, buffers, or anything else that's not even path-like. | 
| 178 | 177 |  """ | 
| 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, pathlib.Path): | 
| 191 |  | - filepath_or_buffer = str(filepath_or_buffer) | 
|  | 178 | + if isinstance(filepath_or_buffer, os.PathLike): | 
|  | 179 | + filepath_or_buffer = filepath_or_buffer.__fspath__() | 
| 192 | 180 |  return _expand_user(filepath_or_buffer) | 
| 193 | 181 | 
 | 
| 194 | 182 | 
 | 
|  | 
0 commit comments