-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-3866 add types to topology_description.py #1339
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
pymongo/topology_description.py
Outdated
] = (server_description.set_version, server_description.election_id) | ||
max_election_tuple: Union[ | ||
Tuple[Optional[int], Optional[ObjectId]], Tuple[Optional[ObjectId], Optional[int]] | ||
] = (max_set_version, max_election_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do these need explicit hints? It makes this code significantly less readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Um the other alternative that I see is to just type it as Tuple
and not specify the contents. By default, mypy will assume new_election_tuple
to be a tuple of Optional[int]
, Optional[OblectId]
. however, it gets reassigned to be a tuple of Optional[ObjectId]
, Optional[int]
which mypy then complains about.
I've changed it to now just be Tuple
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see the problem is that mypy considers the two vars to be overlapping even though they are never used in the same scope. Yeah I think bare Tuple is fine.
s for s in selection.server_descriptions if (s.round_trip_time - fastest) <= threshold | ||
s | ||
for s in selection.server_descriptions | ||
if (cast(float, s.round_trip_time) - fastest) <= threshold |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I wonder if we could use float("inf")
as the round trip time for unknown servers rather than None. Could you open a ticket for that idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah!
https://jira.mongodb.org/browse/PYTHON-3866