Skip to content

Commit ae8ecc4

Browse files
committed
fix typing
1 parent c847f25 commit ae8ecc4

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

pymongo/ssl_support.py

+12-13
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
"""Support for SSL in PyMongo."""
1616
from __future__ import annotations
1717

18+
import types
1819
import warnings
19-
from typing import Optional
20+
from typing import Any, Optional, Union
2021

2122
from pymongo.errors import ConfigurationError
2223

@@ -60,15 +61,15 @@
6061
BLOCKING_IO_LOOKUP_ERROR = BLOCKING_IO_READ_ERROR
6162

6263
if HAVE_PYSSL:
63-
PYSSLError = _pyssl.SSLError
64-
PYBLOCKING_IO_ERRORS = _pyssl.BLOCKING_IO_ERRORS
65-
PYBLOCKING_IO_READ_ERROR = _pyssl.BLOCKING_IO_READ_ERROR
66-
PYBLOCKING_IO_WRITE_ERROR = _pyssl.BLOCKING_IO_WRITE_ERROR
67-
PYBLOCKING_IO_LOOKUP_ERROR = BLOCKING_IO_READ_ERROR
64+
PYSSLError: Any = _pyssl.SSLError
65+
PYBLOCKING_IO_ERRORS: Any = _pyssl.BLOCKING_IO_ERRORS
66+
PYBLOCKING_IO_READ_ERROR: Any = _pyssl.BLOCKING_IO_READ_ERROR
67+
PYBLOCKING_IO_WRITE_ERROR: Any = _pyssl.BLOCKING_IO_WRITE_ERROR
68+
PYBLOCKING_IO_LOOKUP_ERROR: Any = BLOCKING_IO_READ_ERROR
6869
else:
6970
# just make them the same as SSL so imports won't error
7071
PYSSLError = _ssl.SSLError
71-
PYBLOCKING_IO_ERRORS = ()
72+
PYBLOCKING_IO_ERRORS = _ssl.BLOCKING_IO_ERRORS
7273
PYBLOCKING_IO_READ_ERROR = _ssl.BLOCKING_IO_READ_ERROR
7374
PYBLOCKING_IO_WRITE_ERROR = _ssl.BLOCKING_IO_WRITE_ERROR
7475
PYBLOCKING_IO_LOOKUP_ERROR = BLOCKING_IO_READ_ERROR
@@ -82,14 +83,14 @@ def get_ssl_context(
8283
allow_invalid_hostnames: bool,
8384
disable_ocsp_endpoint_check: bool,
8485
is_sync: bool,
85-
) -> _ssl.SSLContext:
86+
) -> Union[_pyssl.SSLContext, _ssl.SSLContext]: # type: ignore[name-defined]
8687
"""Create and return an SSLContext object."""
8788
if is_sync and HAVE_PYSSL:
88-
ssl_in_use = _pyssl
89+
ssl_in_use: types.ModuleType = _pyssl
8990
else:
9091
ssl_in_use = _ssl
9192
verify_mode = CERT_NONE if allow_invalid_certificates else CERT_REQUIRED
92-
ctx = _ssl.SSLContext(_ssl.PROTOCOL_SSLv23)
93+
ctx = ssl_in_use.SSLContext(ssl_in_use.PROTOCOL_SSLv23)
9394
if verify_mode != CERT_NONE:
9495
ctx.check_hostname = not allow_invalid_hostnames
9596
else:
@@ -114,9 +115,7 @@ def get_ssl_context(
114115
if ssl_in_use.IS_PYOPENSSL:
115116
raise ConfigurationError("tlsCRLFile cannot be used with PyOpenSSL")
116117
# Match the server's behavior.
117-
ctx.verify_flags = getattr( # type:ignore[attr-defined]
118-
ssl_in_use, "VERIFY_CRL_CHECK_LEAF", 0
119-
)
118+
ctx.verify_flags = getattr(ssl_in_use, "VERIFY_CRL_CHECK_LEAF", 0)
120119
ctx.load_verify_locations(crlfile)
121120
if ca_certs is not None:
122121
ctx.load_verify_locations(ca_certs)

pymongo/uri_parser_shared.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ def _check_options(nodes: Sized, options: Mapping[str, Any]) -> None:
421421

422422

423423
def _parse_kms_tls_options(
424-
kms_tls_options: Optional[Mapping[str, Any]], is_sync
424+
kms_tls_options: Optional[Mapping[str, Any]],
425+
is_sync: bool,
425426
) -> dict[str, SSLContext]:
426427
"""Parse KMS TLS connection options."""
427428
if not kms_tls_options:

0 commit comments

Comments
 (0)