98
98
from pymongo .topology import Topology , _ErrorContext
99
99
from pymongo .topology_description import TOPOLOGY_TYPE , TopologyDescription
100
100
from pymongo .typings import (
101
+ ClusterTime ,
101
102
_Address ,
102
103
_CollationIn ,
103
104
_DocumentType ,
@@ -1106,10 +1107,10 @@ def primary(self) -> Optional[Tuple[str, int]]:
1106
1107
.. versionadded:: 3.0
1107
1108
MongoClient gained this property in version 3.0.
1108
1109
"""
1109
- return self ._topology .get_primary ()
1110
+ return self ._topology .get_primary () # type: ignore[return-value]
1110
1111
1111
1112
@property
1112
- def secondaries (self ) -> Set [Tuple [ str , int ] ]:
1113
+ def secondaries (self ) -> Set [_Address ]:
1113
1114
"""The secondary members known to this client.
1114
1115
1115
1116
A sequence of (host, port) pairs. Empty if this client is not
@@ -1122,7 +1123,7 @@ def secondaries(self) -> Set[Tuple[str, int]]:
1122
1123
return self ._topology .get_secondaries ()
1123
1124
1124
1125
@property
1125
- def arbiters (self ) -> Set [Tuple [ str , int ] ]:
1126
+ def arbiters (self ) -> Set [_Address ]:
1126
1127
"""Arbiters in the replica set.
1127
1128
1128
1129
A sequence of (host, port) pairs. Empty if this client is not
@@ -1729,7 +1730,7 @@ def _kill_cursors(
1729
1730
if address :
1730
1731
# address could be a tuple or _CursorAddress, but
1731
1732
# select_server_by_address needs (host, port).
1732
- server = topology .select_server_by_address (tuple (address ))
1733
+ server = topology .select_server_by_address (tuple (address )) # type: ignore[arg-type]
1733
1734
else :
1734
1735
# Application called close_cursor() with no address.
1735
1736
server = topology .select_server (writable_server_selector )
@@ -1906,7 +1907,7 @@ def _send_cluster_time(
1906
1907
session_time = session .cluster_time if session else None
1907
1908
if topology_time and session_time :
1908
1909
if topology_time ["clusterTime" ] > session_time ["clusterTime" ]:
1909
- cluster_time = topology_time
1910
+ cluster_time : Optional [ ClusterTime ] = topology_time
1910
1911
else :
1911
1912
cluster_time = session_time
1912
1913
else :
@@ -2271,7 +2272,7 @@ def contribute_socket(self, conn: Connection, completed_handshake: bool = True)
2271
2272
def handle (
2272
2273
self , exc_type : Optional [Type [BaseException ]], exc_val : Optional [BaseException ]
2273
2274
) -> None :
2274
- if self .handled or exc_type is None :
2275
+ if self .handled or exc_val is None :
2275
2276
return
2276
2277
self .handled = True
2277
2278
if self .session :
@@ -2285,7 +2286,6 @@ def handle(
2285
2286
"RetryableWriteError"
2286
2287
):
2287
2288
self .session ._unpin ()
2288
-
2289
2289
err_ctx = _ErrorContext (
2290
2290
exc_val ,
2291
2291
self .max_wire_version ,
@@ -2300,8 +2300,8 @@ def __enter__(self) -> _MongoClientErrorHandler:
2300
2300
2301
2301
def __exit__ (
2302
2302
self ,
2303
- exc_type : Optional [Type [BaseException ]],
2304
- exc_val : Optional [BaseException ],
2303
+ exc_type : Optional [Type [Exception ]],
2304
+ exc_val : Optional [Exception ],
2305
2305
exc_tb : Optional [TracebackType ],
2306
2306
) -> None :
2307
2307
return self .handle (exc_type , exc_val )
0 commit comments