From 48b271c862283273c4047ff8776c56ffa5646160 Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Mon, 13 Mar 2017 18:33:02 +0300 Subject: [PATCH 1/5] Update stub for builtin `open` function due to PEP-519. --- stdlib/3/builtins.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index b0669b118a14..93df5edef03d 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -795,8 +795,8 @@ def next(i: Iterator[_T], default: _VT) -> Union[_T, _VT]: ... def oct(i: int) -> str: ... # TODO __index__ if sys.version_info >= (3, 6): - from pathlib import Path - def open(file: Union[str, bytes, int, Path], mode: str = 'r', buffering: int = -1, encoding: str = None, + from os import PathLike + def open(file: Union[str, bytes, int, PathLike], mode: str = 'r', buffering: int = -1, encoding: str = None, errors: str = None, newline: str = None, closefd: bool = ...) -> IO[Any]: ... else: def open(file: Union[str, bytes, int], mode: str = 'r', buffering: int = -1, encoding: str = None, From 10860386d8db00072332529dde41b398051a8ab0 Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Mon, 13 Mar 2017 18:34:18 +0300 Subject: [PATCH 2/5] Update stubs for `os.path`, `os.fsencode` and `os.fsdecode` functions due to PEP-519. --- stdlib/3/os/__init__.pyi | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/stdlib/3/os/__init__.pyi b/stdlib/3/os/__init__.pyi index ecf894e14c77..b193595611cd 100644 --- a/stdlib/3/os/__init__.pyi +++ b/stdlib/3/os/__init__.pyi @@ -182,8 +182,24 @@ class statvfs_result: # Unix only f_namemax = 0 # ----- os function stubs ----- -def fsencode(filename: str) -> bytes: ... -def fsdecode(filename: bytes) -> str: ... +if sys.version_info >= (3, 6): + def fsencode(filename: Union[str, PathLike]) -> bytes: ... +else: + def fsencode(filename: str) -> bytes: ... + +if sys.version_info >= (3, 6): + def fsdecode(filename: Union[bytes, PathLike]) -> str: ... +else: + def fsdecode(filename: bytes) -> str: ... + +if sys.version_info >= (3, 6): + @overload + def fspath(path: str) -> str: ... + @overload + def fspath(path: bytes) -> bytes: ... + @overload + def fspath(path: PathLike) -> Union[str, bytes]: ... + def get_exec_path(env: Optional[Mapping[str, str]] = ...) -> List[str]: ... # NOTE: get_exec_path(): returns List[bytes] when env not None def ctermid() -> str: ... # Unix only From e4fdd0eb628269eb34decadb3f44a7a18d353e04 Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Mon, 13 Mar 2017 18:35:50 +0300 Subject: [PATCH 3/5] Update stubs for `pathlib.PurePath` and `pathlib.Path` classes due to PEP-519. --- stdlib/3.4/pathlib.pyi | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/stdlib/3.4/pathlib.pyi b/stdlib/3.4/pathlib.pyi index ef142a7c7fb0..796bce01cb99 100644 --- a/stdlib/3.4/pathlib.pyi +++ b/stdlib/3.4/pathlib.pyi @@ -22,8 +22,10 @@ class PurePath(_PurePathBase): stem = ... # type: str if sys.version_info < (3, 5): def __init__(self, *pathsegments: str) -> None: ... - else: + 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 __hash__(self) -> int: ... def __lt__(self, other: PurePath) -> bool: ... def __le__(self, other: PurePath) -> bool: ... @@ -93,8 +95,12 @@ class Path(PurePath): if sys.version_info >= (3, 5): @classmethod def home(cls: Type[_P]) -> _P: ... - def __new__(cls: Type[_P], *args: Union[str, PurePath], - **kwargs: Any) -> _P: ... + if sys.version_info < (3, 6): + def __new__(cls: Type[_P], *args: Union[str, PurePath], + **kwargs: Any) -> _P: ... + else: + def __new__(cls: Type[_P], *args: Union[str, os.PathLike], + **kwargs: Any) -> _P: ... def absolute(self: _P) -> _P: ... def expanduser(self: _P) -> _P: ... From 99a1afd72b241c46ddfdb6c655b8697996d4fe24 Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Sat, 18 Mar 2017 18:12:27 +0300 Subject: [PATCH 4/5] Update input parameter type for `os.fsencode` (+bytes) and `os.fsdecode` (+str). --- stdlib/3/os/__init__.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/3/os/__init__.pyi b/stdlib/3/os/__init__.pyi index b193595611cd..34f697d088fc 100644 --- a/stdlib/3/os/__init__.pyi +++ b/stdlib/3/os/__init__.pyi @@ -183,14 +183,14 @@ class statvfs_result: # Unix only # ----- os function stubs ----- if sys.version_info >= (3, 6): - def fsencode(filename: Union[str, PathLike]) -> bytes: ... + def fsencode(filename: Union[str, bytes, PathLike]) -> bytes: ... else: - def fsencode(filename: str) -> bytes: ... + def fsencode(filename: Union[str, bytes]) -> bytes: ... if sys.version_info >= (3, 6): - def fsdecode(filename: Union[bytes, PathLike]) -> str: ... + def fsdecode(filename: Union[str, bytes, PathLike]) -> str: ... else: - def fsdecode(filename: bytes) -> str: ... + def fsdecode(filename: Union[str, bytes]) -> str: ... if sys.version_info >= (3, 6): @overload From 89de36afa4bd75cc49369626e3e8aa3190075042 Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Tue, 21 Mar 2017 15:00:46 +0300 Subject: [PATCH 5/5] Update `os.fspath(path: PathLike)` to return `Any` since `Union` return types are troublesome --- stdlib/3/os/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3/os/__init__.pyi b/stdlib/3/os/__init__.pyi index 34f697d088fc..27d3780d8147 100644 --- a/stdlib/3/os/__init__.pyi +++ b/stdlib/3/os/__init__.pyi @@ -198,7 +198,7 @@ if sys.version_info >= (3, 6): @overload def fspath(path: bytes) -> bytes: ... @overload - def fspath(path: PathLike) -> Union[str, bytes]: ... + def fspath(path: PathLike) -> Any: ... def get_exec_path(env: Optional[Mapping[str, str]] = ...) -> List[str]: ... # NOTE: get_exec_path(): returns List[bytes] when env not None