Skip to content

PathLike: change to Protocol #4447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions stdlib/2/__builtin__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we put this in _typeshed?

Copy link
Collaborator Author

@hauntsaninja hauntsaninja Aug 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer not to... even if it can be made to work, it'll involve a mypy-typeshed dance (and maybe changes to other type checkers) for little benefit.
Plus _typeshed is for making types internally reusable, and PathLike is already internally (and externally) reusable from os

def __fspath__(self) -> _AnyStr_co: ...
def compile(
source: Union[str, bytes, mod, AST],
filename: Union[str, bytes, _PathLike[Any]],
Expand Down
5 changes: 3 additions & 2 deletions stdlib/2and3/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand Down
2 changes: 1 addition & 1 deletion stdlib/3/os/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down