diff --git a/stdlib/@python2/__builtin__.pyi b/stdlib/@python2/__builtin__.pyi index 8f42584aa..092f9d47b 100644 --- a/stdlib/@python2/__builtin__.pyi +++ b/stdlib/@python2/__builtin__.pyi @@ -43,7 +43,6 @@ from typing import ( Union, ValuesView, overload, - runtime_checkable, ) from typing_extensions import Literal @@ -838,15 +837,6 @@ def cmp(__x: Any, __y: Any) -> int: ... _N1 = TypeVar("_N1", bool, int, float, complex) def coerce(__x: _N1, __y: _N1) -> Tuple[_N1, _N1]: ... - -# This class is to be exported as PathLike from os, -# but we define it here as _PathLike to avoid import cycle issues. -# See https://github.com/python/typeshed/pull/991#issuecomment-288160993 -_AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True) -@runtime_checkable -class _PathLike(Protocol[_AnyStr_co]): - def __fspath__(self) -> _AnyStr_co: ... - def compile(source: Union[Text, mod], filename: Text, mode: Text, flags: int = ..., dont_inherit: int = ...) -> Any: ... def delattr(__obj: Any, __name: Text) -> None: ... def dir(__o: object = ...) -> List[str]: ... diff --git a/stdlib/@python2/builtins.pyi b/stdlib/@python2/builtins.pyi index 8f42584aa..092f9d47b 100644 --- a/stdlib/@python2/builtins.pyi +++ b/stdlib/@python2/builtins.pyi @@ -43,7 +43,6 @@ from typing import ( Union, ValuesView, overload, - runtime_checkable, ) from typing_extensions import Literal @@ -838,15 +837,6 @@ def cmp(__x: Any, __y: Any) -> int: ... _N1 = TypeVar("_N1", bool, int, float, complex) def coerce(__x: _N1, __y: _N1) -> Tuple[_N1, _N1]: ... - -# This class is to be exported as PathLike from os, -# but we define it here as _PathLike to avoid import cycle issues. -# See https://github.com/python/typeshed/pull/991#issuecomment-288160993 -_AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True) -@runtime_checkable -class _PathLike(Protocol[_AnyStr_co]): - def __fspath__(self) -> _AnyStr_co: ... - def compile(source: Union[Text, mod], filename: Text, mode: Text, flags: int = ..., dont_inherit: int = ...) -> Any: ... def delattr(__obj: Any, __name: Text) -> None: ... def dir(__o: object = ...) -> List[str]: ... diff --git a/stdlib/@python2/os/__init__.pyi b/stdlib/@python2/os/__init__.pyi index c43b24f2b..7b32f5087 100644 --- a/stdlib/@python2/os/__init__.pyi +++ b/stdlib/@python2/os/__init__.pyi @@ -153,11 +153,6 @@ if sys.platform != "win32": TMP_MAX: int # Undocumented, but used by tempfile # ----- os classes (structures) ----- -if sys.version_info >= (3, 6): - from builtins import _PathLike - - PathLike = _PathLike # See comment in builtins - class _StatVFS(NamedTuple): f_bsize: int f_frsize: int diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 174fed83f..81316654d 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -57,7 +57,6 @@ from typing import ( Union, ValuesView, overload, - runtime_checkable, ) from typing_extensions import Literal, SupportsIndex @@ -959,11 +958,10 @@ if sys.version_info >= (3, 7): def callable(__obj: object) -> bool: ... def chr(__i: int) -> str: ... -# This class is to be exported as PathLike from os, -# but we define it here as _PathLike to avoid import cycle issues. +# We define this here instead of using os.PathLike to avoid import cycle issues. # See https://github.com/python/typeshed/pull/991#issuecomment-288160993 _AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True) -@runtime_checkable + class _PathLike(Protocol[_AnyStr_co]): def __fspath__(self) -> _AnyStr_co: ... diff --git a/stdlib/genericpath.pyi b/stdlib/genericpath.pyi index 8171354d1..fc314f0a1 100644 --- a/stdlib/genericpath.pyi +++ b/stdlib/genericpath.pyi @@ -1,5 +1,6 @@ import sys -from typing import AnyStr, Sequence, Text, Union +from _typeshed import AnyPath +from typing import AnyStr, Sequence, Text if sys.version_info >= (3, 0): def commonprefix(m: Sequence[str]) -> str: ... @@ -7,13 +8,7 @@ if sys.version_info >= (3, 0): else: def commonprefix(m: Sequence[AnyStr]) -> AnyStr: ... -if sys.version_info >= (3, 6): - from builtins import _PathLike - def exists(path: Union[AnyStr, _PathLike[AnyStr]]) -> bool: ... - -else: - def exists(path: Text) -> bool: ... - +def exists(path: AnyPath) -> bool: ... def isfile(path: Text) -> bool: ... def isdir(s: Text) -> bool: ... def getsize(filename: Text) -> int: ... diff --git a/stdlib/http/server.pyi b/stdlib/http/server.pyi index 7d61bc4d2..f9a13d013 100644 --- a/stdlib/http/server.pyi +++ b/stdlib/http/server.pyi @@ -1,11 +1,9 @@ import email.message import socketserver import sys +from os import PathLike from typing import Any, ClassVar, Dict, List, Mapping, Optional, Sequence, Tuple, Union -if sys.version_info >= (3, 7): - from builtins import _PathLike - class HTTPServer(socketserver.TCPServer): server_name: str server_port: int @@ -59,7 +57,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): request: bytes, client_address: Tuple[str, int], server: socketserver.BaseServer, - directory: Optional[Union[str, _PathLike[str]]] = ..., + directory: Optional[Union[str, PathLike[str]]] = ..., ) -> None: ... else: def __init__(self, request: bytes, client_address: Tuple[str, int], server: socketserver.BaseServer) -> None: ... diff --git a/stdlib/importlib/abc.pyi b/stdlib/importlib/abc.pyi index 8915b2859..47f7f071a 100644 --- a/stdlib/importlib/abc.pyi +++ b/stdlib/importlib/abc.pyi @@ -1,6 +1,6 @@ -import os import sys import types +from _typeshed import AnyPath from abc import ABCMeta, abstractmethod from typing import IO, Any, Iterator, Mapping, Optional, Sequence, Tuple, Union from typing_extensions import Literal @@ -62,12 +62,11 @@ class FileLoader(ResourceLoader, ExecutionLoader, metaclass=ABCMeta): def load_module(self, name: Optional[str] = ...) -> types.ModuleType: ... if sys.version_info >= (3, 7): - _PathLike = Union[bytes, str, os.PathLike[Any]] class ResourceReader(metaclass=ABCMeta): @abstractmethod - def open_resource(self, resource: _PathLike) -> IO[bytes]: ... + def open_resource(self, resource: AnyPath) -> IO[bytes]: ... @abstractmethod - def resource_path(self, resource: _PathLike) -> str: ... + def resource_path(self, resource: AnyPath) -> str: ... @abstractmethod def is_resource(self, name: str) -> bool: ... @abstractmethod diff --git a/stdlib/macpath.pyi b/stdlib/macpath.pyi index 0b5ccbf05..2a8177660 100644 --- a/stdlib/macpath.pyi +++ b/stdlib/macpath.pyi @@ -7,7 +7,7 @@ if sys.version_info < (3, 8): _T = TypeVar("_T") if sys.version_info >= (3, 6): - from builtins import _PathLike + from os import PathLike # ----- os.path variables ----- supports_unicode_filenames: bool @@ -25,35 +25,35 @@ if sys.version_info < (3, 8): if sys.version_info >= (3, 6): # Overloads are necessary to work around python/mypy#3644. @overload - def abspath(path: _PathLike[AnyStr]) -> AnyStr: ... + def abspath(path: PathLike[AnyStr]) -> AnyStr: ... @overload def abspath(path: AnyStr) -> AnyStr: ... @overload - def basename(s: _PathLike[AnyStr]) -> AnyStr: ... + def basename(s: PathLike[AnyStr]) -> AnyStr: ... @overload def basename(s: AnyStr) -> AnyStr: ... @overload - def dirname(s: _PathLike[AnyStr]) -> AnyStr: ... + def dirname(s: PathLike[AnyStr]) -> AnyStr: ... @overload def dirname(s: AnyStr) -> AnyStr: ... @overload - def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ... + def expanduser(path: PathLike[AnyStr]) -> AnyStr: ... @overload def expanduser(path: AnyStr) -> AnyStr: ... @overload - def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ... + def expandvars(path: PathLike[AnyStr]) -> AnyStr: ... @overload def expandvars(path: AnyStr) -> AnyStr: ... @overload - def normcase(path: _PathLike[AnyStr]) -> AnyStr: ... + def normcase(path: PathLike[AnyStr]) -> AnyStr: ... @overload def normcase(path: AnyStr) -> AnyStr: ... @overload - def normpath(s: _PathLike[AnyStr]) -> AnyStr: ... + def normpath(s: PathLike[AnyStr]) -> AnyStr: ... @overload def normpath(s: AnyStr) -> AnyStr: ... @overload - def realpath(path: _PathLike[AnyStr]) -> AnyStr: ... + def realpath(path: PathLike[AnyStr]) -> AnyStr: ... @overload def realpath(path: AnyStr) -> AnyStr: ... else: @@ -113,15 +113,15 @@ if sys.version_info < (3, 8): def samestat(s1: os.stat_result, s2: os.stat_result) -> bool: ... if sys.version_info >= (3, 6): @overload - def split(s: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + def split(s: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def split(s: AnyStr) -> Tuple[AnyStr, AnyStr]: ... @overload - def splitdrive(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + def splitdrive(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def splitdrive(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... @overload - def splitext(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + def splitext(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def splitext(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... else: diff --git a/stdlib/ntpath.pyi b/stdlib/ntpath.pyi index 33536f751..4ee1b31c6 100644 --- a/stdlib/ntpath.pyi +++ b/stdlib/ntpath.pyi @@ -1,8 +1,8 @@ import os import sys from _typeshed import AnyPath, BytesPath, StrPath -from builtins import _PathLike from genericpath import exists as exists +from os import PathLike from typing import Any, AnyStr, Optional, Sequence, Tuple, TypeVar, overload _T = TypeVar("_T") @@ -25,43 +25,43 @@ devnull: str # ----- os.path function stubs ----- # Overloads are necessary to work around python/mypy#3644. @overload -def abspath(path: _PathLike[AnyStr]) -> AnyStr: ... +def abspath(path: PathLike[AnyStr]) -> AnyStr: ... @overload def abspath(path: AnyStr) -> AnyStr: ... @overload -def basename(p: _PathLike[AnyStr]) -> AnyStr: ... +def basename(p: PathLike[AnyStr]) -> AnyStr: ... @overload def basename(p: AnyStr) -> AnyStr: ... @overload -def dirname(p: _PathLike[AnyStr]) -> AnyStr: ... +def dirname(p: PathLike[AnyStr]) -> AnyStr: ... @overload def dirname(p: AnyStr) -> AnyStr: ... @overload -def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ... +def expanduser(path: PathLike[AnyStr]) -> AnyStr: ... @overload def expanduser(path: AnyStr) -> AnyStr: ... @overload -def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ... +def expandvars(path: PathLike[AnyStr]) -> AnyStr: ... @overload def expandvars(path: AnyStr) -> AnyStr: ... @overload -def normcase(s: _PathLike[AnyStr]) -> AnyStr: ... +def normcase(s: PathLike[AnyStr]) -> AnyStr: ... @overload def normcase(s: AnyStr) -> AnyStr: ... @overload -def normpath(path: _PathLike[AnyStr]) -> AnyStr: ... +def normpath(path: PathLike[AnyStr]) -> AnyStr: ... @overload def normpath(path: AnyStr) -> AnyStr: ... if sys.platform == "win32": @overload - def realpath(path: _PathLike[AnyStr]) -> AnyStr: ... + def realpath(path: PathLike[AnyStr]) -> AnyStr: ... @overload def realpath(path: AnyStr) -> AnyStr: ... else: @overload - def realpath(filename: _PathLike[AnyStr]) -> AnyStr: ... + def realpath(filename: PathLike[AnyStr]) -> AnyStr: ... @overload def realpath(filename: AnyStr) -> AnyStr: ... @@ -97,15 +97,15 @@ def samefile(f1: AnyPath, f2: AnyPath) -> bool: ... def sameopenfile(fp1: int, fp2: int) -> bool: ... def samestat(s1: os.stat_result, s2: os.stat_result) -> bool: ... @overload -def split(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... +def split(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def split(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... @overload -def splitdrive(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... +def splitdrive(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def splitdrive(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... @overload -def splitext(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... +def splitext(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def splitext(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... diff --git a/stdlib/os/__init__.pyi b/stdlib/os/__init__.pyi index f88f9c6a9..7a426bfdc 100644 --- a/stdlib/os/__init__.pyi +++ b/stdlib/os/__init__.pyi @@ -8,7 +8,7 @@ from _typeshed import ( OpenBinaryModeWriting, OpenTextMode, ) -from builtins import OSError, _PathLike +from builtins import OSError from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper as _TextIOWrapper from posix import listdir as listdir, times_result from subprocess import Popen @@ -28,12 +28,14 @@ from typing import ( MutableMapping, NoReturn, Optional, + Protocol, Sequence, Set, Tuple, TypeVar, Union, overload, + runtime_checkable, ) from typing_extensions import Literal @@ -46,6 +48,7 @@ if sys.version_info >= (3, 9): _supports_unicode_filenames = path.supports_unicode_filenames _T = TypeVar("_T") +_AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True) # ----- os variables ----- @@ -301,7 +304,9 @@ class stat_result: st_creator: int st_type: int -PathLike = _PathLike # See comment in builtins +@runtime_checkable +class PathLike(Protocol[_AnyStr_co]): + def __fspath__(self) -> _AnyStr_co: ... _FdOrAnyPath = Union[int, AnyPath] diff --git a/stdlib/os/path.pyi b/stdlib/os/path.pyi index 9fe5a7df6..2fcbe12f8 100644 --- a/stdlib/os/path.pyi +++ b/stdlib/os/path.pyi @@ -1,8 +1,8 @@ import os import sys from _typeshed import AnyPath, BytesPath, StrPath -from builtins import _PathLike from genericpath import exists as exists +from os import PathLike from typing import Any, AnyStr, Optional, Sequence, Tuple, TypeVar, overload _T = TypeVar("_T") @@ -25,43 +25,43 @@ devnull: str # ----- os.path function stubs ----- # Overloads are necessary to work around python/mypy#3644. @overload -def abspath(path: _PathLike[AnyStr]) -> AnyStr: ... +def abspath(path: PathLike[AnyStr]) -> AnyStr: ... @overload def abspath(path: AnyStr) -> AnyStr: ... @overload -def basename(p: _PathLike[AnyStr]) -> AnyStr: ... +def basename(p: PathLike[AnyStr]) -> AnyStr: ... @overload def basename(p: AnyStr) -> AnyStr: ... @overload -def dirname(p: _PathLike[AnyStr]) -> AnyStr: ... +def dirname(p: PathLike[AnyStr]) -> AnyStr: ... @overload def dirname(p: AnyStr) -> AnyStr: ... @overload -def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ... +def expanduser(path: PathLike[AnyStr]) -> AnyStr: ... @overload def expanduser(path: AnyStr) -> AnyStr: ... @overload -def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ... +def expandvars(path: PathLike[AnyStr]) -> AnyStr: ... @overload def expandvars(path: AnyStr) -> AnyStr: ... @overload -def normcase(s: _PathLike[AnyStr]) -> AnyStr: ... +def normcase(s: PathLike[AnyStr]) -> AnyStr: ... @overload def normcase(s: AnyStr) -> AnyStr: ... @overload -def normpath(path: _PathLike[AnyStr]) -> AnyStr: ... +def normpath(path: PathLike[AnyStr]) -> AnyStr: ... @overload def normpath(path: AnyStr) -> AnyStr: ... if sys.platform == "win32": @overload - def realpath(path: _PathLike[AnyStr]) -> AnyStr: ... + def realpath(path: PathLike[AnyStr]) -> AnyStr: ... @overload def realpath(path: AnyStr) -> AnyStr: ... else: @overload - def realpath(filename: _PathLike[AnyStr]) -> AnyStr: ... + def realpath(filename: PathLike[AnyStr]) -> AnyStr: ... @overload def realpath(filename: AnyStr) -> AnyStr: ... @@ -97,15 +97,15 @@ def samefile(f1: AnyPath, f2: AnyPath) -> bool: ... def sameopenfile(fp1: int, fp2: int) -> bool: ... def samestat(s1: os.stat_result, s2: os.stat_result) -> bool: ... @overload -def split(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... +def split(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def split(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... @overload -def splitdrive(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... +def splitdrive(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def splitdrive(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... @overload -def splitext(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... +def splitext(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def splitext(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... diff --git a/stdlib/pathlib.pyi b/stdlib/pathlib.pyi index cd00398fe..b4624c3be 100644 --- a/stdlib/pathlib.pyi +++ b/stdlib/pathlib.pyi @@ -1,7 +1,7 @@ -import os import sys -from _typeshed import OpenBinaryMode, OpenBinaryModeReading, OpenBinaryModeUpdating, OpenBinaryModeWriting, OpenTextMode +from _typeshed import OpenBinaryMode, OpenBinaryModeReading, OpenBinaryModeUpdating, OpenBinaryModeWriting, OpenTextMode, StrPath from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper +from os import PathLike, stat_result from types import TracebackType from typing import IO, Any, BinaryIO, Generator, List, Optional, Sequence, Tuple, Type, TypeVar, Union, overload from typing_extensions import Literal @@ -11,10 +11,7 @@ if sys.version_info >= (3, 9): _P = TypeVar("_P", bound=PurePath) -_PurePathBase = os.PathLike[str] -_PathLike = os.PathLike[str] - -class PurePath(_PurePathBase): +class PurePath(PathLike[str]): parts: Tuple[str, ...] drive: str root: str @@ -23,28 +20,28 @@ class PurePath(_PurePathBase): suffix: str suffixes: List[str] stem: str - def __new__(cls: Type[_P], *args: Union[str, _PathLike]) -> _P: ... + def __new__(cls: Type[_P], *args: StrPath) -> _P: ... def __hash__(self) -> int: ... def __lt__(self, other: PurePath) -> bool: ... def __le__(self, other: PurePath) -> bool: ... def __gt__(self, other: PurePath) -> bool: ... def __ge__(self, other: PurePath) -> bool: ... - def __truediv__(self: _P, key: Union[str, _PathLike]) -> _P: ... - def __rtruediv__(self: _P, key: Union[str, _PathLike]) -> _P: ... + def __truediv__(self: _P, key: StrPath) -> _P: ... + def __rtruediv__(self: _P, key: StrPath) -> _P: ... def __bytes__(self) -> bytes: ... def as_posix(self) -> str: ... def as_uri(self) -> str: ... def is_absolute(self) -> bool: ... def is_reserved(self) -> bool: ... if sys.version_info >= (3, 9): - def is_relative_to(self, *other: Union[str, os.PathLike[str]]) -> bool: ... + def is_relative_to(self, *other: StrPath) -> bool: ... def match(self, path_pattern: str) -> bool: ... - def relative_to(self: _P, *other: Union[str, _PathLike]) -> _P: ... + def relative_to(self: _P, *other: StrPath) -> _P: ... def with_name(self: _P, name: str) -> _P: ... if sys.version_info >= (3, 9): def with_stem(self: _P, stem: str) -> _P: ... def with_suffix(self: _P, suffix: str) -> _P: ... - def joinpath(self: _P, *other: Union[str, _PathLike]) -> _P: ... + def joinpath(self: _P, *other: StrPath) -> _P: ... @property def parents(self: _P) -> Sequence[_P]: ... @property @@ -56,14 +53,14 @@ class PurePosixPath(PurePath): ... class PureWindowsPath(PurePath): ... class Path(PurePath): - def __new__(cls: Type[_P], *args: Union[str, _PathLike], **kwargs: Any) -> _P: ... + def __new__(cls: Type[_P], *args: StrPath, **kwargs: Any) -> _P: ... def __enter__(self: _P) -> _P: ... def __exit__( self, exc_type: Optional[Type[BaseException]], exc_value: Optional[BaseException], traceback: Optional[TracebackType] ) -> Optional[bool]: ... @classmethod def cwd(cls: Type[_P]) -> _P: ... - def stat(self) -> os.stat_result: ... + def stat(self) -> stat_result: ... def chmod(self, mode: int) -> None: ... def exists(self) -> bool: ... def glob(self: _P, pattern: str) -> Generator[_P, None, None]: ... @@ -79,7 +76,7 @@ class Path(PurePath): def is_char_device(self) -> bool: ... def iterdir(self: _P) -> Generator[_P, None, None]: ... def lchmod(self, mode: int) -> None: ... - def lstat(self) -> os.stat_result: ... + def lstat(self) -> stat_result: ... def mkdir(self, mode: int = ..., parents: bool = ..., exist_ok: bool = ...) -> None: ... # Adapted from builtins.open # Text mode: always returns a TextIOWrapper @@ -168,7 +165,7 @@ class Path(PurePath): def write_bytes(self, data: bytes) -> int: ... def write_text(self, data: str, encoding: Optional[str] = ..., errors: Optional[str] = ...) -> int: ... if sys.version_info >= (3, 8): - def link_to(self, target: Union[str, bytes, os.PathLike[str]]) -> None: ... + def link_to(self, target: Union[StrPath, bytes]) -> None: ... class PosixPath(Path, PurePosixPath): ... class WindowsPath(Path, PureWindowsPath): ... diff --git a/stdlib/posix.pyi b/stdlib/posix.pyi index 9080d5b90..1a9dc4264 100644 --- a/stdlib/posix.pyi +++ b/stdlib/posix.pyi @@ -1,6 +1,5 @@ import sys -from builtins import _PathLike # See comment in builtins -from os import stat_result as stat_result +from os import PathLike, stat_result as stat_result from typing import Dict, List, NamedTuple, Optional, overload class uname_result(NamedTuple): @@ -157,7 +156,7 @@ def listdir(path: bytes) -> List[bytes]: ... @overload def listdir(path: int) -> List[str]: ... @overload -def listdir(path: _PathLike[str]) -> List[str]: ... +def listdir(path: PathLike[str]) -> List[str]: ... if sys.platform == "win32": environ: Dict[str, str] diff --git a/stdlib/posixpath.pyi b/stdlib/posixpath.pyi index 9fe5a7df6..2fcbe12f8 100644 --- a/stdlib/posixpath.pyi +++ b/stdlib/posixpath.pyi @@ -1,8 +1,8 @@ import os import sys from _typeshed import AnyPath, BytesPath, StrPath -from builtins import _PathLike from genericpath import exists as exists +from os import PathLike from typing import Any, AnyStr, Optional, Sequence, Tuple, TypeVar, overload _T = TypeVar("_T") @@ -25,43 +25,43 @@ devnull: str # ----- os.path function stubs ----- # Overloads are necessary to work around python/mypy#3644. @overload -def abspath(path: _PathLike[AnyStr]) -> AnyStr: ... +def abspath(path: PathLike[AnyStr]) -> AnyStr: ... @overload def abspath(path: AnyStr) -> AnyStr: ... @overload -def basename(p: _PathLike[AnyStr]) -> AnyStr: ... +def basename(p: PathLike[AnyStr]) -> AnyStr: ... @overload def basename(p: AnyStr) -> AnyStr: ... @overload -def dirname(p: _PathLike[AnyStr]) -> AnyStr: ... +def dirname(p: PathLike[AnyStr]) -> AnyStr: ... @overload def dirname(p: AnyStr) -> AnyStr: ... @overload -def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ... +def expanduser(path: PathLike[AnyStr]) -> AnyStr: ... @overload def expanduser(path: AnyStr) -> AnyStr: ... @overload -def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ... +def expandvars(path: PathLike[AnyStr]) -> AnyStr: ... @overload def expandvars(path: AnyStr) -> AnyStr: ... @overload -def normcase(s: _PathLike[AnyStr]) -> AnyStr: ... +def normcase(s: PathLike[AnyStr]) -> AnyStr: ... @overload def normcase(s: AnyStr) -> AnyStr: ... @overload -def normpath(path: _PathLike[AnyStr]) -> AnyStr: ... +def normpath(path: PathLike[AnyStr]) -> AnyStr: ... @overload def normpath(path: AnyStr) -> AnyStr: ... if sys.platform == "win32": @overload - def realpath(path: _PathLike[AnyStr]) -> AnyStr: ... + def realpath(path: PathLike[AnyStr]) -> AnyStr: ... @overload def realpath(path: AnyStr) -> AnyStr: ... else: @overload - def realpath(filename: _PathLike[AnyStr]) -> AnyStr: ... + def realpath(filename: PathLike[AnyStr]) -> AnyStr: ... @overload def realpath(filename: AnyStr) -> AnyStr: ... @@ -97,15 +97,15 @@ def samefile(f1: AnyPath, f2: AnyPath) -> bool: ... def sameopenfile(fp1: int, fp2: int) -> bool: ... def samestat(s1: os.stat_result, s2: os.stat_result) -> bool: ... @overload -def split(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... +def split(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def split(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... @overload -def splitdrive(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... +def splitdrive(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def splitdrive(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ... @overload -def splitext(p: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... +def splitext(p: PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... @overload def splitext(p: AnyStr) -> Tuple[AnyStr, AnyStr]: ...