More fixes related to PathLike (#1061)

* Make DirEntry generic over AnyStr, and inherit from PathLike if it exists

* Make pathlib require PathLike[str] (when it exists)
This commit is contained in:
Guido van Rossum
2017-03-21 22:26:21 -07:00
committed by Jelle Zijlstra
parent 7587e7f1c1
commit af2fadc180
2 changed files with 23 additions and 9 deletions

View File

@@ -7,7 +7,7 @@ import sys
_P = TypeVar('_P', bound='PurePath')
if sys.version_info >= (3, 6):
_PurePathBase = os.PathLike
_PurePathBase = os.PathLike[str]
else:
_PurePathBase = object
@@ -25,7 +25,7 @@ class PurePath(_PurePathBase):
elif sys.version_info < (3, 6):
def __new__(cls: Type[_P], *args: Union[str, PurePath]) -> _P: ...
else:
def __new__(cls: Type[_P], *args: Union[str, os.PathLike]) -> _P: ...
def __new__(cls: Type[_P], *args: Union[str, os.PathLike[str]]) -> _P: ...
def __hash__(self) -> int: ...
def __lt__(self, other: PurePath) -> bool: ...
def __le__(self, other: PurePath) -> bool: ...
@@ -99,7 +99,7 @@ class Path(PurePath):
def __new__(cls: Type[_P], *args: Union[str, PurePath],
**kwargs: Any) -> _P: ...
else:
def __new__(cls: Type[_P], *args: Union[str, os.PathLike],
def __new__(cls: Type[_P], *args: Union[str, os.PathLike[str]],
**kwargs: Any) -> _P: ...
def absolute(self: _P) -> _P: ...