Skip to content

Commit

Permalink
Using os.PathLike instead of pathlib.Path (#37979) (#38018)
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhi-H authored Dec 2, 2020
1 parent e2564fd commit c4c1dc3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
4 changes: 2 additions & 2 deletions pandas/_typing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime, timedelta, tzinfo
from io import BufferedIOBase, RawIOBase, TextIOBase, TextIOWrapper
from mmap import mmap
from pathlib import Path
from os import PathLike
from typing import (
IO,
TYPE_CHECKING,
Expand Down Expand Up @@ -135,7 +135,7 @@
# filenames and file-like-objects
Buffer = Union[IO[AnyStr], RawIOBase, BufferedIOBase, TextIOBase, TextIOWrapper, mmap]
FileOrBuffer = Union[str, Buffer[T]]
FilePathOrBuffer = Union[Path, FileOrBuffer[T]]
FilePathOrBuffer = Union["PathLike[str]", FileOrBuffer[T]]

# for arbitrary kwargs passed during reading/writing files
StorageOptions = Optional[Dict[str, Any]]
Expand Down
16 changes: 2 additions & 14 deletions pandas/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from io import BufferedIOBase, BytesIO, RawIOBase, TextIOWrapper
import mmap
import os
import pathlib
from typing import IO, Any, AnyStr, Dict, List, Mapping, Optional, Tuple, cast
from urllib.parse import (
urljoin,
Expand Down Expand Up @@ -176,19 +175,8 @@ def stringify_path(
Any other object is passed through unchanged, which includes bytes,
strings, buffers, or anything else that's not even path-like.
"""
if hasattr(filepath_or_buffer, "__fspath__"):
# https://github.com/python/mypy/issues/1424
# error: Item "str" of "Union[str, Path, IO[str]]" has no attribute
# "__fspath__" [union-attr]
# error: Item "IO[str]" of "Union[str, Path, IO[str]]" has no attribute
# "__fspath__" [union-attr]
# error: Item "str" of "Union[str, Path, IO[bytes]]" has no attribute
# "__fspath__" [union-attr]
# error: Item "IO[bytes]" of "Union[str, Path, IO[bytes]]" has no
# attribute "__fspath__" [union-attr]
filepath_or_buffer = filepath_or_buffer.__fspath__() # type: ignore[union-attr]
elif isinstance(filepath_or_buffer, pathlib.Path):
filepath_or_buffer = str(filepath_or_buffer)
if isinstance(filepath_or_buffer, os.PathLike):
filepath_or_buffer = filepath_or_buffer.__fspath__()
return _expand_user(filepath_or_buffer)


Expand Down

0 comments on commit c4c1dc3

Please sign in to comment.