Skip to content

PYTHON-3867 add types to topology.py #1346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
17 changes: 8 additions & 9 deletions pymongo/mongo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,10 +1106,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 +1122,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 +1729,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 +1906,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: Optional[Mapping[str, Any]] = topology_time
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use ClusterTime here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea!

else:
cluster_time = session_time
else:
Expand Down Expand Up @@ -2271,7 +2271,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 +2285,6 @@ def handle(
"RetryableWriteError"
):
self.session._unpin()

err_ctx = _ErrorContext(
exc_val,
self.max_wire_version,
Expand All @@ -2300,8 +2299,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/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