Skip to content

Commit a229746

Browse files
committed
Type error fixes
1 parent 8ca4b0e commit a229746

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

pymongo/asynchronous/encryption.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,14 @@ def __init__(
143143
self._spawned = False
144144

145145
async def _async_kms_request(
146-
self, kms_context: MongoCryptKmsContext, host, port, opts, message
146+
self,
147+
kms_context: MongoCryptKmsContext,
148+
host: str,
149+
port: Optional[int],
150+
opts: PoolOptions,
151+
message: bytes,
147152
) -> None:
148-
from pymongo.network_layer import _async_receive_data_socket
153+
from pymongo.network_layer import async_receive_data_socket # type: ignore[attr-defined]
149154

150155
try:
151156
conn = await _configured_socket((host, port), opts)
@@ -154,7 +159,7 @@ async def _async_kms_request(
154159
while kms_context.bytes_needed > 0:
155160
# CSOT: update timeout.
156161
conn.settimeout(max(_csot.clamp_remaining(_KMS_CONNECT_TIMEOUT), 0))
157-
data = await _async_receive_data_socket(conn, kms_context.bytes_needed)
162+
data = await async_receive_data_socket(conn, kms_context.bytes_needed)
158163
kms_context.feed(data)
159164
except OSError as err:
160165
raise OSError("KMS connection closed") from err

pymongo/network_layer.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,9 @@ async def async_receive_data(
277277
sock.settimeout(sock_timeout)
278278

279279

280-
async def _async_receive_data_socket(sock: socket.socket | _sslConn, length: int) -> memoryview:
280+
async def async_receive_data_socket(
281+
sock: Union[socket.socket, _sslConn], length: int
282+
) -> memoryview:
281283
sock_timeout = sock.gettimeout()
282284
timeout = sock_timeout
283285

@@ -286,8 +288,9 @@ async def _async_receive_data_socket(sock: socket.socket | _sslConn, length: int
286288
try:
287289
if _HAVE_SSL and isinstance(sock, (SSLSocket, _sslConn)):
288290
return await asyncio.wait_for(
289-
_async_receive_ssl(sock, length, loop, once=True), timeout=timeout
290-
) # type: ignore[arg-type]
291+
_async_receive_ssl(sock, length, loop, once=True), # type: ignore[arg-type]
292+
timeout=timeout,
293+
)
291294
else:
292295
return await asyncio.wait_for(_async_receive(sock, length, loop), timeout=timeout) # type: ignore[arg-type]
293296
except asyncio.TimeoutError as err:

pymongo/synchronous/encryption.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,14 @@ def __init__(
143143
self._spawned = False
144144

145145
def _async_kms_request(
146-
self, kms_context: MongoCryptKmsContext, host, port, opts, message
146+
self,
147+
kms_context: MongoCryptKmsContext,
148+
host: str,
149+
port: Optional[int],
150+
opts: PoolOptions,
151+
message: bytes,
147152
) -> None:
148-
from pymongo.network_layer import _receive_data_socket
153+
from pymongo.network_layer import receive_data_socket # type: ignore[attr-defined]
149154

150155
try:
151156
conn = _configured_socket((host, port), opts)
@@ -154,7 +159,7 @@ def _async_kms_request(
154159
while kms_context.bytes_needed > 0:
155160
# CSOT: update timeout.
156161
conn.settimeout(max(_csot.clamp_remaining(_KMS_CONNECT_TIMEOUT), 0))
157-
data = _receive_data_socket(conn, kms_context.bytes_needed)
162+
data = receive_data_socket(conn, kms_context.bytes_needed)
158163
kms_context.feed(data)
159164
except OSError as err:
160165
raise OSError("KMS connection closed") from err

0 commit comments

Comments
 (0)