From b43e1db47b8392c50b90c0e75864dd074323f6bc Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Thu, 12 Jan 2023 10:19:41 -0800 Subject: [PATCH] ssl, sysconfig: fix issues with defaults (#9507) - ssl._create_unverified_context allows None since 3.10: https://github.com/python/cpython/commit/2875c603b2a7691b55c2046aca54831c91efda8e#diff-f6439be9c66350dde4c35dbeea0352c96cc970ba12b0478f6ae36f10725bd8c5 - sysconfig.is_python_build ignores its argument since 3.11: https://github.com/python/cpython/commit/067597522a9002f3b8aff7f46033f10acb2381e4 (was backported into 3.11) --- stdlib/ssl.pyi | 40 ++++++++++++++++++++--------- stdlib/sysconfig.pyi | 8 +++++- tests/stubtest_allowlists/py310.txt | 1 - tests/stubtest_allowlists/py311.txt | 7 ----- 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/stdlib/ssl.pyi b/stdlib/ssl.pyi index 91844e836..6d7df5e1c 100644 --- a/stdlib/ssl.pyi +++ b/stdlib/ssl.pyi @@ -63,18 +63,34 @@ def create_default_context( capath: StrOrBytesPath | None = ..., cadata: str | ReadableBuffer | None = ..., ) -> SSLContext: ... -def _create_unverified_context( - protocol: int = ..., - *, - cert_reqs: int = ..., - check_hostname: bool = ..., - purpose: Purpose = ..., - certfile: StrOrBytesPath | None = ..., - keyfile: StrOrBytesPath | None = ..., - cafile: StrOrBytesPath | None = ..., - capath: StrOrBytesPath | None = ..., - cadata: str | ReadableBuffer | None = ..., -) -> SSLContext: ... + +if sys.version_info >= (3, 10): + def _create_unverified_context( + protocol: int | None = None, + *, + cert_reqs: int = ..., + check_hostname: bool = ..., + purpose: Purpose = ..., + certfile: StrOrBytesPath | None = ..., + keyfile: StrOrBytesPath | None = ..., + cafile: StrOrBytesPath | None = ..., + capath: StrOrBytesPath | None = ..., + cadata: str | ReadableBuffer | None = ..., + ) -> SSLContext: ... + +else: + def _create_unverified_context( + protocol: int = ..., + *, + cert_reqs: int = ..., + check_hostname: bool = ..., + purpose: Purpose = ..., + certfile: StrOrBytesPath | None = ..., + keyfile: StrOrBytesPath | None = ..., + cafile: StrOrBytesPath | None = ..., + capath: StrOrBytesPath | None = ..., + cadata: str | ReadableBuffer | None = ..., + ) -> SSLContext: ... _create_default_https_context: Callable[..., SSLContext] diff --git a/stdlib/sysconfig.pyi b/stdlib/sysconfig.pyi index 895abc2cd..4b6257b5f 100644 --- a/stdlib/sysconfig.pyi +++ b/stdlib/sysconfig.pyi @@ -32,7 +32,13 @@ def get_path(name: str, scheme: str = ..., vars: dict[str, Any] | None = ..., ex def get_paths(scheme: str = ..., vars: dict[str, Any] | None = ..., expand: bool = ...) -> dict[str, str]: ... def get_python_version() -> str: ... def get_platform() -> str: ... -def is_python_build(check_home: bool = ...) -> bool: ... + +if sys.version_info >= (3, 11): + def is_python_build(check_home: object = None) -> bool: ... + +else: + def is_python_build(check_home: bool = False) -> bool: ... + def parse_config_h(fp: IO[Any], vars: dict[str, Any] | None = ...) -> dict[str, Any]: ... def get_config_h_filename() -> str: ... def get_makefile_filename() -> str: ... diff --git a/tests/stubtest_allowlists/py310.txt b/tests/stubtest_allowlists/py310.txt index 06e391048..64c2c7079 100644 --- a/tests/stubtest_allowlists/py310.txt +++ b/tests/stubtest_allowlists/py310.txt @@ -55,7 +55,6 @@ unittest.case.TestCase.__init_subclass__ # but in 3.10+ calling the function without the default argument is in fact deprecated, # so it's better to ignore stubtest ssl.SSLContext.__new__ -ssl._create_unverified_context # SpooledTemporaryFile implements IO except these methods before Python 3.11 # See also https://github.com/python/typeshed/pull/2452#issuecomment-420657918 diff --git a/tests/stubtest_allowlists/py311.txt b/tests/stubtest_allowlists/py311.txt index 3c8da1fbb..5da38eae1 100644 --- a/tests/stubtest_allowlists/py311.txt +++ b/tests/stubtest_allowlists/py311.txt @@ -51,7 +51,6 @@ unittest.case.TestCase.__init_subclass__ # but in 3.10+ calling the function without the default argument is in fact deprecated, # so it's better to ignore stubtest ssl.SSLContext.__new__ -ssl._create_unverified_context # ========== # Related to positional-only arguments @@ -128,12 +127,6 @@ ast.ImportFrom.level # None on the class, but never None on instances contextlib.AbstractAsyncContextManager.__class_getitem__ contextlib.AbstractContextManager.__class_getitem__ -# The argument to is_python_build() is deprecated since Python 3.11 and -# has a default value of None to check for its existence and warn if it's -# supplied. None is not supposed to be passed by user code and therefore -# not included in the stubs. -sysconfig.is_python_build - # Super-special typing primitives typing._SpecialForm.__mro_entries__ typing._TypedDict.__delitem__