Skip to content

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

Merged
merged 3 commits into from
Aug 3, 2023

Conversation

sleepyStick
Copy link
Contributor

@sleepyStick sleepyStick marked this pull request as ready for review August 3, 2023 16:27
@sleepyStick sleepyStick requested a review from a team as a code owner August 3, 2023 16:27
@sleepyStick sleepyStick requested review from NoahStapp and removed request for a team August 3, 2023 16:27
Copy link
Contributor

@NoahStapp NoahStapp left a comment

Choose a reason for hiding this comment

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

LGTM!

@NoahStapp NoahStapp requested a review from ShaneHarvey August 3, 2023 19:18
] = (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)
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah!

@sleepyStick sleepyStick merged commit 5484075 into mongodb:master Aug 3, 2023
@sleepyStick sleepyStick deleted the PYTHON-3866 branch August 3, 2023 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants