Skip to content

Commit cc02f1d

Browse files
author
hauntsaninja
committed
PathLike: change to Protocol
1 parent 0ee7b26 commit cc02f1d

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

stdlib/2/__builtin__.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,8 +1207,9 @@ if sys.version_info >= (3, 6):
12071207
# This class is to be exported as PathLike from os,
12081208
# but we define it here as _PathLike to avoid import cycle issues.
12091209
# See https://github.com/python/typeshed/pull/991#issuecomment-288160993
1210-
class _PathLike(Generic[AnyStr]):
1211-
def __fspath__(self) -> AnyStr: ...
1210+
_AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True)
1211+
class _PathLike(Protocol[_AnyStr_co]):
1212+
def __fspath__(self) -> _AnyStr_co: ...
12121213
def compile(
12131214
source: Union[str, bytes, mod, AST],
12141215
filename: Union[str, bytes, _PathLike[Any]],

stdlib/2and3/builtins.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,8 +1207,9 @@ if sys.version_info >= (3, 6):
12071207
# This class is to be exported as PathLike from os,
12081208
# but we define it here as _PathLike to avoid import cycle issues.
12091209
# See https://github.com/python/typeshed/pull/991#issuecomment-288160993
1210-
class _PathLike(Generic[AnyStr]):
1211-
def __fspath__(self) -> AnyStr: ...
1210+
_AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True)
1211+
class _PathLike(Protocol[_AnyStr_co]):
1212+
def __fspath__(self) -> _AnyStr_co: ...
12121213
def compile(
12131214
source: Union[str, bytes, mod, AST],
12141215
filename: Union[str, bytes, _PathLike[Any]],

stdlib/3/os/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ if sys.version_info >= (3, 6):
265265
_FdOrAnyPath = Union[int, AnyPath]
266266

267267
if sys.version_info >= (3, 6):
268-
class DirEntry(PathLike[AnyStr]):
268+
class DirEntry(Generic[AnyStr]):
269269
# This is what the scandir interator yields
270270
# The constructor is hidden
271271

0 commit comments

Comments
 (0)