From 8ffc3c2ad0e3f9b12861ef1fe3a7fe5d98cebb50 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Tue, 31 Jan 2023 12:26:14 +0000 Subject: [PATCH 1/2] Add a default for `ssl.SSLContext.__new__` on 3.10+ --- stdlib/ssl.pyi | 7 ++++++- tests/stubtest_allowlists/py310.txt | 5 ----- tests/stubtest_allowlists/py311.txt | 5 ----- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/stdlib/ssl.pyi b/stdlib/ssl.pyi index 3b68d107246a..875bd70db9c5 100644 --- a/stdlib/ssl.pyi +++ b/stdlib/ssl.pyi @@ -380,7 +380,12 @@ class SSLContext: post_handshake_auth: bool if sys.version_info >= (3, 10): security_level: int - def __new__(cls: type[Self], protocol: int = ..., *args: Any, **kwargs: Any) -> Self: ... + if sys.version_info >= (3, 10): + # Using the default (None) for the `protocol` parameter is deprecated, + # but there isn't a good way of marking that in the stub unless/until PEP 702 is accepted + def __new__(cls: type[Self], protocol: int | None = None, *args: Any, **kwargs: Any) -> Self: ... + else: + def __new__(cls: type[Self], protocol: int = ..., *args: Any, **kwargs: Any) -> Self: ... def cert_store_stats(self) -> dict[str, int]: ... def load_cert_chain( self, certfile: StrOrBytesPath, keyfile: StrOrBytesPath | None = None, password: _PasswordType | None = None diff --git a/tests/stubtest_allowlists/py310.txt b/tests/stubtest_allowlists/py310.txt index 7f53e7f10190..739a3db422c7 100644 --- a/tests/stubtest_allowlists/py310.txt +++ b/tests/stubtest_allowlists/py310.txt @@ -53,11 +53,6 @@ weakref.WeakValueDictionary.update unittest.TestCase.__init_subclass__ unittest.case.TestCase.__init_subclass__ -# stubtest complains that in 3.10 the default argument is inconsistent with the annotation, -# 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__ - # SpooledTemporaryFile implements IO except these methods before Python 3.11 # See also https://github.com/python/typeshed/pull/2452#issuecomment-420657918 tempfile.SpooledTemporaryFile.__next__ diff --git a/tests/stubtest_allowlists/py311.txt b/tests/stubtest_allowlists/py311.txt index b65f27050331..ed6ce05f4870 100644 --- a/tests/stubtest_allowlists/py311.txt +++ b/tests/stubtest_allowlists/py311.txt @@ -47,11 +47,6 @@ weakref.WeakValueDictionary.update unittest.TestCase.__init_subclass__ unittest.case.TestCase.__init_subclass__ -# stubtest complains that in 3.10 the default argument is inconsistent with the annotation, -# 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__ - # ========== # Related to positional-only arguments # ========== From 291877296d606cfc12f091ba83953e63e1e12184 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 31 Jan 2023 12:28:05 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/ssl.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/ssl.pyi b/stdlib/ssl.pyi index 875bd70db9c5..a81bc14e9f81 100644 --- a/stdlib/ssl.pyi +++ b/stdlib/ssl.pyi @@ -386,6 +386,7 @@ class SSLContext: def __new__(cls: type[Self], protocol: int | None = None, *args: Any, **kwargs: Any) -> Self: ... else: def __new__(cls: type[Self], protocol: int = ..., *args: Any, **kwargs: Any) -> Self: ... + def cert_store_stats(self) -> dict[str, int]: ... def load_cert_chain( self, certfile: StrOrBytesPath, keyfile: StrOrBytesPath | None = None, password: _PasswordType | None = None