From b438ccc3bce6d4311b584db7bd762a2ef6ae2a11 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Sun, 16 Aug 2020 05:15:51 -0700 Subject: [PATCH] PathLike: change to Protocol (#4447) Co-authored-by: hauntsaninja <> --- stdlib/2/__builtin__.pyi | 5 +++-- stdlib/2and3/builtins.pyi | 5 +++-- stdlib/3/os/__init__.pyi | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 650a19fa8..ae98b2b0e 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -1207,8 +1207,9 @@ if sys.version_info >= (3, 6): # 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 - class _PathLike(Generic[AnyStr]): - def __fspath__(self) -> AnyStr: ... + _AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True) + class _PathLike(Protocol[_AnyStr_co]): + def __fspath__(self) -> _AnyStr_co: ... def compile( source: Union[str, bytes, mod, AST], filename: Union[str, bytes, _PathLike[Any]], diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index 650a19fa8..ae98b2b0e 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -1207,8 +1207,9 @@ if sys.version_info >= (3, 6): # 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 - class _PathLike(Generic[AnyStr]): - def __fspath__(self) -> AnyStr: ... + _AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True) + class _PathLike(Protocol[_AnyStr_co]): + def __fspath__(self) -> _AnyStr_co: ... def compile( source: Union[str, bytes, mod, AST], filename: Union[str, bytes, _PathLike[Any]], diff --git a/stdlib/3/os/__init__.pyi b/stdlib/3/os/__init__.pyi index e895f21c1..96dc6e572 100644 --- a/stdlib/3/os/__init__.pyi +++ b/stdlib/3/os/__init__.pyi @@ -265,7 +265,7 @@ if sys.version_info >= (3, 6): _FdOrAnyPath = Union[int, AnyPath] if sys.version_info >= (3, 6): - class DirEntry(PathLike[AnyStr]): + class DirEntry(Generic[AnyStr]): # This is what the scandir interator yields # The constructor is hidden