From c522d740160a7ce7c91566dcc7ba02b58c62ba81 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Thu, 28 May 2020 17:50:57 -0400 Subject: [PATCH 1/3] Add platform checks for various sys values --- stdlib/3/sys.pyi | 10 ++++++---- tests/stubtest_whitelists/linux.txt | 1 - tests/stubtest_whitelists/win32.txt | 2 -- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/stdlib/3/sys.pyi b/stdlib/3/sys.pyi index acfce135b2a4..15cf583b2062 100644 --- a/stdlib/3/sys.pyi +++ b/stdlib/3/sys.pyi @@ -19,7 +19,8 @@ _ExcInfo = Tuple[Type[BaseException], BaseException, TracebackType] _OptExcInfo = Union[_ExcInfo, Tuple[None, None, None]] # ----- sys variables ----- -abiflags: str +if sys.platform != "win32": + abiflags: str argv: List[str] base_exec_prefix: str base_prefix: str @@ -179,8 +180,8 @@ class _WinVersion(Tuple[int, int, int, int, product_type: int platform_version: Tuple[int, int, int] - -def getwindowsversion() -> _WinVersion: ... # Windows only +if sys.platform == "win32": + def getwindowsversion() -> _WinVersion: ... # Windows only def intern(__string: str) -> str: ... @@ -190,7 +191,8 @@ if sys.version_info >= (3, 7): __breakpointhook__: Any # contains the original value of breakpointhook def breakpointhook(*args: Any, **kwargs: Any) -> Any: ... -def setdlopenflags(__flags: int) -> None: ... # Linux only +if sys.platform == "linux": + def setdlopenflags(__flags: int) -> None: ... def setrecursionlimit(__limit: int) -> None: ... def setswitchinterval(__interval: float) -> None: ... diff --git a/tests/stubtest_whitelists/linux.txt b/tests/stubtest_whitelists/linux.txt index c64df77a1102..a0b10df46a38 100644 --- a/tests/stubtest_whitelists/linux.txt +++ b/tests/stubtest_whitelists/linux.txt @@ -27,7 +27,6 @@ spwd.getspnam spwd.struct_spwd._asdict spwd.struct_spwd._make spwd.struct_spwd._replace -sys.getwindowsversion time.CLOCK_HIGHRES urllib.request.proxy_bypass diff --git a/tests/stubtest_whitelists/win32.txt b/tests/stubtest_whitelists/win32.txt index 9e22d0b04bd3..cc0e88fb2870 100644 --- a/tests/stubtest_whitelists/win32.txt +++ b/tests/stubtest_whitelists/win32.txt @@ -4,8 +4,6 @@ locale.nl_langinfo # Function that should be moved to _locale and re-exported c os.path.join # Parameter name mismatch posixpath.altsep # Type mismatch posixpath.realpath # Parameter name mismatch -sys.abiflags # Not present -sys.setdlopenflags # Not present urllib.request.pathname2url # Parameter name mismatch urllib.request.url2pathname # Same From ba8e58cc0ef120dea1943685aa29e17fb08caab7 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Thu, 28 May 2020 18:41:45 -0400 Subject: [PATCH 2/3] setdlopenflags is available on unix --- stdlib/3/sys.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3/sys.pyi b/stdlib/3/sys.pyi index 15cf583b2062..9cdbe239ad64 100644 --- a/stdlib/3/sys.pyi +++ b/stdlib/3/sys.pyi @@ -191,7 +191,7 @@ if sys.version_info >= (3, 7): __breakpointhook__: Any # contains the original value of breakpointhook def breakpointhook(*args: Any, **kwargs: Any) -> Any: ... -if sys.platform == "linux": +if sys.platform != "win32": def setdlopenflags(__flags: int) -> None: ... def setrecursionlimit(__limit: int) -> None: ... def setswitchinterval(__interval: float) -> None: ... From e8fbc9ce3d56ca4dcbe018678949bfb71488c5be Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Thu, 28 May 2020 20:10:59 -0400 Subject: [PATCH 3/3] Add windows-only constants, remove extraneous comments --- stdlib/3/sys.pyi | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/stdlib/3/sys.pyi b/stdlib/3/sys.pyi index 9cdbe239ad64..9a8ce9d782f8 100644 --- a/stdlib/3/sys.pyi +++ b/stdlib/3/sys.pyi @@ -27,7 +27,8 @@ base_prefix: str byteorder: str builtin_module_names: Sequence[str] # actually a tuple of strings copyright: str -# dllhandle = 0 # Windows only +if sys.platform == "win32": + dllhandle: int dont_write_bytecode: bool displayhook: Callable[[object], Any] excepthook: Callable[[Type[BaseException], BaseException, TracebackType], Any] @@ -65,7 +66,8 @@ api_version: int warnoptions: Any # Each entry is a tuple of the form (action, message, category, module, # lineno) -# winver = '' # Windows only +if sys.platform == "win32": + winver: str _xoptions: Dict[Any, Any] @@ -142,7 +144,6 @@ def exc_info() -> _OptExcInfo: ... def exit(__status: object = ...) -> NoReturn: ... def getdefaultencoding() -> str: ... if sys.platform != 'win32': - # Unix only def getdlopenflags() -> int: ... def getfilesystemencoding() -> str: ... def getrefcount(__object: Any) -> int: ... @@ -181,7 +182,7 @@ class _WinVersion(Tuple[int, int, int, int, platform_version: Tuple[int, int, int] if sys.platform == "win32": - def getwindowsversion() -> _WinVersion: ... # Windows only + def getwindowsversion() -> _WinVersion: ... def intern(__string: str) -> str: ...