Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pymongo/client_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@

from pymongo.pool import Connection
from pymongo.server import Server
from pymongo.typings import _Address
from pymongo.typings import ClusterTime, _Address


class SessionOptions:
Expand Down Expand Up @@ -562,7 +562,7 @@ def session_id(self) -> Mapping[str, Any]:
return self._server_session.session_id

@property
def cluster_time(self) -> Optional[Mapping[str, Any]]:
def cluster_time(self) -> ClusterTime:
"""The cluster time returned by the last operation executed
in this session.
"""
Expand Down
4 changes: 2 additions & 2 deletions pymongo/hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from bson.objectid import ObjectId
from pymongo import common
from pymongo.server_type import SERVER_TYPE
from pymongo.typings import _DocumentType
from pymongo.typings import ClusterTime, _DocumentType


class HelloCompat:
Expand Down Expand Up @@ -155,7 +155,7 @@ def election_id(self) -> Optional[ObjectId]:
return self._doc.get("electionId")

@property
def cluster_time(self) -> Optional[Mapping[str, Any]]:
def cluster_time(self) -> ClusterTime:
return self._doc.get("$clusterTime")

@property
Expand Down
18 changes: 9 additions & 9 deletions pymongo/mongo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
from pymongo.topology import Topology, _ErrorContext
from pymongo.topology_description import TOPOLOGY_TYPE, TopologyDescription
from pymongo.typings import (
ClusterTime,
_Address,
_CollationIn,
_DocumentType,
Expand Down Expand Up @@ -1106,10 +1107,10 @@ def primary(self) -> Optional[Tuple[str, int]]:
.. versionadded:: 3.0
MongoClient gained this property in version 3.0.
"""
return self._topology.get_primary()
return self._topology.get_primary() # type: ignore[return-value]

@property
def secondaries(self) -> Set[Tuple[str, int]]:
def secondaries(self) -> Set[_Address]:
"""The secondary members known to this client.

A sequence of (host, port) pairs. Empty if this client is not
Expand All @@ -1122,7 +1123,7 @@ def secondaries(self) -> Set[Tuple[str, int]]:
return self._topology.get_secondaries()

@property
def arbiters(self) -> Set[Tuple[str, int]]:
def arbiters(self) -> Set[_Address]:
"""Arbiters in the replica set.

A sequence of (host, port) pairs. Empty if this client is not
Expand Down Expand Up @@ -1729,7 +1730,7 @@ def _kill_cursors(
if address:
# address could be a tuple or _CursorAddress, but
# select_server_by_address needs (host, port).
server = topology.select_server_by_address(tuple(address))
server = topology.select_server_by_address(tuple(address)) # type: ignore[arg-type]
else:
# Application called close_cursor() with no address.
server = topology.select_server(writable_server_selector)
Expand Down Expand Up @@ -1906,7 +1907,7 @@ def _send_cluster_time(
session_time = session.cluster_time if session else None
if topology_time and session_time:
if topology_time["clusterTime"] > session_time["clusterTime"]:
cluster_time = topology_time
cluster_time: ClusterTime = topology_time
else:
cluster_time = session_time
else:
Expand Down Expand Up @@ -2271,7 +2272,7 @@ def contribute_socket(self, conn: Connection, completed_handshake: bool = True)
def handle(
self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException]
) -> None:
if self.handled or exc_type is None:
if self.handled or exc_val is None:
return
self.handled = True
if self.session:
Expand All @@ -2285,7 +2286,6 @@ def handle(
"RetryableWriteError"
):
self.session._unpin()

err_ctx = _ErrorContext(
exc_val,
self.max_wire_version,
Expand All @@ -2300,8 +2300,8 @@ def __enter__(self) -> _MongoClientErrorHandler:

def __exit__(
self,
exc_type: Optional[Type[BaseException]],
exc_val: Optional[BaseException],
exc_type: Optional[Type[Exception]],
exc_val: Optional[Exception],
exc_tb: Optional[TracebackType],
) -> None:
return self.handle(exc_type, exc_val)
Expand Down
4 changes: 2 additions & 2 deletions pymongo/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
from pymongo.read_concern import ReadConcern
from pymongo.read_preferences import _ServerMode
from pymongo.server_api import ServerApi
from pymongo.typings import _Address, _CollationIn
from pymongo.typings import ClusterTime, _Address, _CollationIn
from pymongo.write_concern import WriteConcern

try:
Expand Down Expand Up @@ -779,7 +779,7 @@ def hello(self) -> Hello[Dict[str, Any]]:

def _hello(
self,
cluster_time: Optional[Mapping[str, Any]],
cluster_time: ClusterTime,
topology_version: Optional[Any],
heartbeat_frequency: Optional[int],
) -> Hello[Dict[str, Any]]:
Expand Down
4 changes: 2 additions & 2 deletions pymongo/server_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from bson.objectid import ObjectId
from pymongo.hello import Hello
from pymongo.server_type import SERVER_TYPE
from pymongo.typings import _Address
from pymongo.typings import ClusterTime, _Address


class ServerDescription:
Expand Down Expand Up @@ -176,7 +176,7 @@ def election_id(self) -> Optional[ObjectId]:
return self._election_id

@property
def cluster_time(self) -> Optional[Mapping[str, Any]]:
def cluster_time(self) -> ClusterTime:
return self._cluster_time

@property
Expand Down
4 changes: 2 additions & 2 deletions pymongo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ def pool_options(self) -> PoolOptions:
return self._pool_options

@property
def monitor_class(self) -> Optional[Type[monitor.Monitor]]:
def monitor_class(self) -> Type[monitor.Monitor]:
return self._monitor_class

@property
def condition_class(self) -> Optional[Type[threading.Condition]]:
def condition_class(self) -> Type[threading.Condition]:
return self._condition_class

@property
Expand Down
Loading