Skip to content

Commit 25464cf

Browse files
Merge pull request #991 from JetBrains/sproshev/pep-519
Update `open`, `os.fspath`, `os.fsencode`, `os.fsdecode`, `pathlib.PurePath` and `pathlib.Path` stubs due to PEP-519
2 parents c8fd855 + 89de36a commit 25464cf

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

stdlib/3.4/pathlib.pyi

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ class PurePath(_PurePathBase):
2222
stem = ... # type: str
2323
if sys.version_info < (3, 5):
2424
def __init__(self, *pathsegments: str) -> None: ...
25-
else:
25+
elif sys.version_info < (3, 6):
2626
def __new__(cls: Type[_P], *args: Union[str, PurePath]) -> _P: ...
27+
else:
28+
def __new__(cls: Type[_P], *args: Union[str, os.PathLike]) -> _P: ...
2729
def __hash__(self) -> int: ...
2830
def __lt__(self, other: PurePath) -> bool: ...
2931
def __le__(self, other: PurePath) -> bool: ...
@@ -93,8 +95,12 @@ class Path(PurePath):
9395
if sys.version_info >= (3, 5):
9496
@classmethod
9597
def home(cls: Type[_P]) -> _P: ...
96-
def __new__(cls: Type[_P], *args: Union[str, PurePath],
97-
**kwargs: Any) -> _P: ...
98+
if sys.version_info < (3, 6):
99+
def __new__(cls: Type[_P], *args: Union[str, PurePath],
100+
**kwargs: Any) -> _P: ...
101+
else:
102+
def __new__(cls: Type[_P], *args: Union[str, os.PathLike],
103+
**kwargs: Any) -> _P: ...
98104

99105
def absolute(self: _P) -> _P: ...
100106
def expanduser(self: _P) -> _P: ...

stdlib/3/builtins.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,8 @@ def next(i: Iterator[_T], default: _VT) -> Union[_T, _VT]: ...
799799
def oct(i: int) -> str: ... # TODO __index__
800800

801801
if sys.version_info >= (3, 6):
802-
from pathlib import Path
803-
def open(file: Union[str, bytes, int, Path], mode: str = 'r', buffering: int = -1, encoding: str = None,
802+
from os import PathLike
803+
def open(file: Union[str, bytes, int, PathLike], mode: str = 'r', buffering: int = -1, encoding: str = None,
804804
errors: str = None, newline: str = None, closefd: bool = ...) -> IO[Any]: ...
805805
else:
806806
def open(file: Union[str, bytes, int], mode: str = 'r', buffering: int = -1, encoding: str = None,

stdlib/3/os/__init__.pyi

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,24 @@ class statvfs_result: # Unix only
189189
f_namemax = 0
190190

191191
# ----- os function stubs -----
192-
def fsencode(filename: str) -> bytes: ...
193-
def fsdecode(filename: bytes) -> str: ...
192+
if sys.version_info >= (3, 6):
193+
def fsencode(filename: Union[str, bytes, PathLike]) -> bytes: ...
194+
else:
195+
def fsencode(filename: Union[str, bytes]) -> bytes: ...
196+
197+
if sys.version_info >= (3, 6):
198+
def fsdecode(filename: Union[str, bytes, PathLike]) -> str: ...
199+
else:
200+
def fsdecode(filename: Union[str, bytes]) -> str: ...
201+
202+
if sys.version_info >= (3, 6):
203+
@overload
204+
def fspath(path: str) -> str: ...
205+
@overload
206+
def fspath(path: bytes) -> bytes: ...
207+
@overload
208+
def fspath(path: PathLike) -> Any: ...
209+
194210
def get_exec_path(env: Optional[Mapping[str, str]] = ...) -> List[str]: ...
195211
# NOTE: get_exec_path(): returns List[bytes] when env not None
196212
def ctermid() -> str: ... # Unix only

0 commit comments

Comments
 (0)