diff --git a/pandas/io/common.py b/pandas/io/common.py index e506cc155d48d..c4772895afd1e 100644 --- a/pandas/io/common.py +++ b/pandas/io/common.py @@ -7,7 +7,19 @@ import mmap import os import pathlib -from typing import IO, Any, AnyStr, Dict, List, Mapping, Optional, Tuple, Union +from typing import ( + IO, + TYPE_CHECKING, + Any, + AnyStr, + Dict, + List, + Mapping, + Optional, + Tuple, + Type, + Union, +) from urllib.parse import ( # noqa urlencode, urljoin, @@ -37,6 +49,10 @@ _VALID_URLS.discard("") +if TYPE_CHECKING: + from io import IOBase # noqa: F401 + + def is_url(url) -> bool: """ Check to see if a URL has a valid protocol. @@ -356,12 +372,13 @@ def get_handle( handles : list of file-like objects A list of file-like object that were opened in this function. """ + need_text_wrapping: Tuple[Type["IOBase"], ...] try: from s3fs import S3File need_text_wrapping = (BufferedIOBase, RawIOBase, S3File) except ImportError: - need_text_wrapping = (BufferedIOBase, RawIOBase) # type: ignore + need_text_wrapping = (BufferedIOBase, RawIOBase) handles: List[IO] = list() f = path_or_buf