Fix typing errors

This commit is contained in:
Jeffrey 'Alex' Clark 2026-05-05 21:04:07 -04:00
parent 75298bcd43
commit b194f2aefa
4 changed files with 12 additions and 10 deletions

View File

@ -40,7 +40,7 @@ from pymongo.errors import (
NotPrimaryError,
OperationFailure,
)
from pymongo.message import _OpMsg
from pymongo.message import _OpMsg, _OpReply
from pymongo.monitoring import _is_speculative_authenticate
if TYPE_CHECKING:
@ -83,7 +83,7 @@ async def _network_command_core(
cursor_id: Optional[int] = None,
orig: Optional[MutableMapping[str, Any]] = None,
speculative_hello: bool = False,
) -> tuple[list[_DocumentOut], Optional[_OpMsg], datetime.timedelta]:
) -> tuple[list[_DocumentOut], Optional[Union[_OpReply, _OpMsg]], datetime.timedelta]:
"""Send/receive a command and return (docs, raw_reply, duration).
Handles APM logging, send/receive, unpacking, response processing,
@ -92,7 +92,7 @@ async def _network_command_core(
"""
publish = listeners is not None and listeners.enabled_for_commands
name = next(iter(spec))
reply: Optional[_OpMsg] = None
reply: Optional[Union[_OpReply, _OpMsg]] = None
docs: list[_DocumentOut] = []
if client is not None:
@ -213,7 +213,7 @@ async def _network_command_core(
if client and client._encrypter and reply is not None:
decrypted = await client._encrypter.decrypt(reply.raw_command_response())
decrypt_fields = _CURSOR_DOC_FIELDS if unpack_res is not None else user_fields
docs = list(_decode_all_selective(decrypted, codec_options, decrypt_fields))
docs = list(_decode_all_selective(decrypted, codec_options, decrypt_fields)) # type: ignore[arg-type]
return docs, reply, duration

View File

@ -155,7 +155,7 @@ class Server:
start = datetime.now()
operation.use_command(conn)
more_to_come = operation.conn_mgr and operation.conn_mgr.more_to_come
more_to_come = bool(operation.conn_mgr and operation.conn_mgr.more_to_come)
cmd, dbn = await self.operation_to_command(operation, conn, True)
if more_to_come:
request_id = 0
@ -186,6 +186,7 @@ class Server:
cursor_id=operation.cursor_id,
)
assert reply is not None
response: Response
client = operation.client # type: ignore[assignment]
if client._should_pin_cursor(operation.session) or operation.exhaust: # type: ignore[arg-type]

View File

@ -40,7 +40,7 @@ from pymongo.errors import (
NotPrimaryError,
OperationFailure,
)
from pymongo.message import _OpMsg
from pymongo.message import _OpMsg, _OpReply
from pymongo.monitoring import _is_speculative_authenticate
if TYPE_CHECKING:
@ -83,7 +83,7 @@ def _network_command_core(
cursor_id: Optional[int] = None,
orig: Optional[MutableMapping[str, Any]] = None,
speculative_hello: bool = False,
) -> tuple[list[_DocumentOut], Optional[_OpMsg], datetime.timedelta]:
) -> tuple[list[_DocumentOut], Optional[Union[_OpReply, _OpMsg]], datetime.timedelta]:
"""Send/receive a command and return (docs, raw_reply, duration).
Handles APM logging, send/receive, unpacking, response processing,
@ -92,7 +92,7 @@ def _network_command_core(
"""
publish = listeners is not None and listeners.enabled_for_commands
name = next(iter(spec))
reply: Optional[_OpMsg] = None
reply: Optional[Union[_OpReply, _OpMsg]] = None
docs: list[_DocumentOut] = []
if client is not None:
@ -213,7 +213,7 @@ def _network_command_core(
if client and client._encrypter and reply is not None:
decrypted = client._encrypter.decrypt(reply.raw_command_response())
decrypt_fields = _CURSOR_DOC_FIELDS if unpack_res is not None else user_fields
docs = list(_decode_all_selective(decrypted, codec_options, decrypt_fields))
docs = list(_decode_all_selective(decrypted, codec_options, decrypt_fields)) # type: ignore[arg-type]
return docs, reply, duration

View File

@ -155,7 +155,7 @@ class Server:
start = datetime.now()
operation.use_command(conn)
more_to_come = operation.conn_mgr and operation.conn_mgr.more_to_come
more_to_come = bool(operation.conn_mgr and operation.conn_mgr.more_to_come)
cmd, dbn = self.operation_to_command(operation, conn, True)
if more_to_come:
request_id = 0
@ -186,6 +186,7 @@ class Server:
cursor_id=operation.cursor_id,
)
assert reply is not None
response: Response
client = operation.client # type: ignore[assignment]
if client._should_pin_cursor(operation.session) or operation.exhaust: # type: ignore[arg-type]