9898from pymongo .topology import Topology , _ErrorContext
9999from pymongo .topology_description import TOPOLOGY_TYPE , TopologyDescription
100100from pymongo .typings import (
101+ ClusterTime ,
101102 _Address ,
102103 _CollationIn ,
103104 _DocumentType ,
@@ -1106,10 +1107,10 @@ def primary(self) -> Optional[Tuple[str, int]]:
11061107 .. versionadded:: 3.0
11071108 MongoClient gained this property in version 3.0.
11081109 """
1109- return self ._topology .get_primary ()
1110+ return self ._topology .get_primary () # type: ignore[return-value]
11101111
11111112 @property
1112- def secondaries (self ) -> Set [Tuple [ str , int ] ]:
1113+ def secondaries (self ) -> Set [_Address ]:
11131114 """The secondary members known to this client.
11141115
11151116 A sequence of (host, port) pairs. Empty if this client is not
@@ -1122,7 +1123,7 @@ def secondaries(self) -> Set[Tuple[str, int]]:
11221123 return self ._topology .get_secondaries ()
11231124
11241125 @property
1125- def arbiters (self ) -> Set [Tuple [ str , int ] ]:
1126+ def arbiters (self ) -> Set [_Address ]:
11261127 """Arbiters in the replica set.
11271128
11281129 A sequence of (host, port) pairs. Empty if this client is not
@@ -1729,7 +1730,7 @@ def _kill_cursors(
17291730 if address :
17301731 # address could be a tuple or _CursorAddress, but
17311732 # 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]
17331734 else :
17341735 # Application called close_cursor() with no address.
17351736 server = topology .select_server (writable_server_selector )
@@ -1906,7 +1907,7 @@ def _send_cluster_time(
19061907 session_time = session .cluster_time if session else None
19071908 if topology_time and session_time :
19081909 if topology_time ["clusterTime" ] > session_time ["clusterTime" ]:
1909- cluster_time = topology_time
1910+ cluster_time : Optional [ ClusterTime ] = topology_time
19101911 else :
19111912 cluster_time = session_time
19121913 else :
@@ -2271,7 +2272,7 @@ def contribute_socket(self, conn: Connection, completed_handshake: bool = True)
22712272 def handle (
22722273 self , exc_type : Optional [Type [BaseException ]], exc_val : Optional [BaseException ]
22732274 ) -> None :
2274- if self .handled or exc_type is None :
2275+ if self .handled or exc_val is None :
22752276 return
22762277 self .handled = True
22772278 if self .session :
@@ -2285,7 +2286,6 @@ def handle(
22852286 "RetryableWriteError"
22862287 ):
22872288 self .session ._unpin ()
2288-
22892289 err_ctx = _ErrorContext (
22902290 exc_val ,
22912291 self .max_wire_version ,
@@ -2300,8 +2300,8 @@ def __enter__(self) -> _MongoClientErrorHandler:
23002300
23012301 def __exit__ (
23022302 self ,
2303- exc_type : Optional [Type [BaseException ]],
2304- exc_val : Optional [BaseException ],
2303+ exc_type : Optional [Type [Exception ]],
2304+ exc_val : Optional [Exception ],
23052305 exc_tb : Optional [TracebackType ],
23062306 ) -> None :
23072307 return self .handle (exc_type , exc_val )
0 commit comments