From e1e579bd50cbc58df8e75593eba31a4e3ee165e1 Mon Sep 17 00:00:00 2001 From: Steven Kalt Date: Thu, 21 Nov 2019 12:20:58 -0500 Subject: [PATCH 1/3] draft compileall.pyi fix for #3475 --- stdlib/3/compileall.pyi | 85 ++++++++++++++++++++++++++++++----------- 1 file changed, 63 insertions(+), 22 deletions(-) diff --git a/stdlib/3/compileall.pyi b/stdlib/3/compileall.pyi index 276cb5bef304..80392b691218 100644 --- a/stdlib/3/compileall.pyi +++ b/stdlib/3/compileall.pyi @@ -11,25 +11,66 @@ else: _Path = Union[str, bytes, os.PathLike] _SuccessType = int -# rx can be any object with a 'search' method; once we have Protocols we can change the type -def compile_dir( - dir: _Path, - maxlevels: int = ..., - ddir: Optional[_Path] = ..., - force: bool = ..., - rx: Optional[Pattern[Any]] = ..., - quiet: int = ..., - legacy: bool = ..., - optimize: int = ..., - workers: int = ..., -) -> _SuccessType: ... -def compile_file( - fullname: _Path, - ddir: Optional[_Path] = ..., - force: bool = ..., - rx: Optional[Pattern[Any]] = ..., - quiet: int = ..., - legacy: bool = ..., - optimize: int = ..., -) -> _SuccessType: ... -def compile_path(skip_curdir: bool = ..., maxlevels: int = ..., force: bool = ..., quiet: int = ..., legacy: bool = ..., optimize: int = ...) -> _SuccessType: ... +if sys.version_info >= (3, 7): + from py_compile import PycInvalidationMode + def compile_dir( + dir: _Path, + maxlevels: int = ..., + ddir: Optional[_Path] = ..., + force: bool = ..., + rx: Optional[Pattern[Any]] = ..., + quiet: int = ..., + legacy: bool = ..., + optimize: int = ..., + workers: int = ..., + invalidation_mode: PycInvalidationMode = ..., + ) -> _SuccessType: ... + def compile_file( + fullname: _Path, + ddir: Optional[_Path] = ..., + force: bool = ..., + rx: Optional[Pattern[Any]] = ..., + quiet: int = ..., + legacy: bool = ..., + optimize: int = ..., + invalidation_mode: PycInvalidationMode = ..., + ) -> _SuccessType: ... + def compile_path( + skip_curdir: bool = ..., + maxlevels: int = ..., + force: bool = ..., + quiet: int = ..., + legacy: bool = ..., + optimize: int = ..., + invalidation_mode: PycInvalidationMode = ..., + ) -> _SuccessType: ... +else: + # rx can be any object with a 'search' method; once we have Protocols we can change the type + def compile_dir( + dir: _Path, + maxlevels: int = ..., + ddir: Optional[_Path] = ..., + force: bool = ..., + rx: Optional[Pattern[Any]] = ..., + quiet: int = ..., + legacy: bool = ..., + optimize: int = ..., + workers: int = ..., + ) -> _SuccessType: ... + def compile_file( + fullname: _Path, + ddir: Optional[_Path] = ..., + force: bool = ..., + rx: Optional[Pattern[Any]] = ..., + quiet: int = ..., + legacy: bool = ..., + optimize: int = ..., + ) -> _SuccessType: ... + def compile_path( + skip_curdir: bool = ..., + maxlevels: int = ..., + force: bool = ..., + quiet: int = ..., + legacy: bool = ..., + optimize: int = ... + ) -> _SuccessType: ... From 3599b523af785b5b6875864f024807a652bcd862 Mon Sep 17 00:00:00 2001 From: Steven Kalt Date: Thu, 21 Nov 2019 12:51:39 -0500 Subject: [PATCH 2/3] `black`ed the changed file --- stdlib/3/compileall.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/3/compileall.pyi b/stdlib/3/compileall.pyi index 80392b691218..7070f68dd20a 100644 --- a/stdlib/3/compileall.pyi +++ b/stdlib/3/compileall.pyi @@ -44,6 +44,7 @@ if sys.version_info >= (3, 7): optimize: int = ..., invalidation_mode: PycInvalidationMode = ..., ) -> _SuccessType: ... + else: # rx can be any object with a 'search' method; once we have Protocols we can change the type def compile_dir( @@ -72,5 +73,5 @@ else: force: bool = ..., quiet: int = ..., legacy: bool = ..., - optimize: int = ... + optimize: int = ..., ) -> _SuccessType: ... From 36af1a631beb357e865c628f0dfd39bb9ee3f460 Mon Sep 17 00:00:00 2001 From: Steven Kalt Date: Sat, 23 Nov 2019 09:14:38 -0500 Subject: [PATCH 3/3] correction: PycInvalidationMode is Optional --- stdlib/3/compileall.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/3/compileall.pyi b/stdlib/3/compileall.pyi index 7070f68dd20a..72f5d4cab2a7 100644 --- a/stdlib/3/compileall.pyi +++ b/stdlib/3/compileall.pyi @@ -23,7 +23,7 @@ if sys.version_info >= (3, 7): legacy: bool = ..., optimize: int = ..., workers: int = ..., - invalidation_mode: PycInvalidationMode = ..., + invalidation_mode: Optional[PycInvalidationMode] = ..., ) -> _SuccessType: ... def compile_file( fullname: _Path, @@ -33,7 +33,7 @@ if sys.version_info >= (3, 7): quiet: int = ..., legacy: bool = ..., optimize: int = ..., - invalidation_mode: PycInvalidationMode = ..., + invalidation_mode: Optional[PycInvalidationMode] = ..., ) -> _SuccessType: ... def compile_path( skip_curdir: bool = ..., @@ -42,7 +42,7 @@ if sys.version_info >= (3, 7): quiet: int = ..., legacy: bool = ..., optimize: int = ..., - invalidation_mode: PycInvalidationMode = ..., + invalidation_mode: Optional[PycInvalidationMode] = ..., ) -> _SuccessType: ... else: