Skip to content

PYTHON-4903 Adds typing overloading to bson.binary.Binary.from_vector #1967

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

Conversation

caseyclements
Copy link
Contributor

Follows suggestion from @ShaneHarvey that adding typing oveloading would make clear that dtype is a required argument when the first argument, vector, is a list, not at BinaryVector instance.

Copy link
Member

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

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

We should also remove the BETA and add a changelog entry

Copy link
Member

@ShaneHarvey ShaneHarvey left a comment

Choose a reason for hiding this comment

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

Do we have a test that from_vector(BinaryVector(), dtype=...) raises an error and requires a type-ignore?

@@ -802,6 +802,13 @@ def test_vector(self):
assert float_binary == Binary.from_vector(
BinaryVector(list_vector, BinaryVectorDtype.FLOAT32)
)
# Confirm kwargs cannot be passed when BinaryVector is provided
self.assertRaises(
Copy link
Member

Choose a reason for hiding this comment

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

Can you write this as a with self.assertRaises(): so we can confirm a "type-ignore" is detected?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure can. How do we confirm that a type-ignore is detected?

        with self.assertRaises(ValueError):
            Binary.from_vector(
                BinaryVector(list_vector, BinaryVectorDtype.PACKED_BIT, padding),
                dtype=BinaryVectorDtype.PACKED_BIT
            )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh.... I see. This will fail linting without it.

Copy link
Member

Choose a reason for hiding this comment

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

Yep that's what I was thinking!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TIL. Thanks @ShaneHarvey ! This was a very cool lesson.

@caseyclements caseyclements merged commit 466d0a1 into mongodb:master Nov 5, 2024
27 of 29 checks passed
@caseyclements caseyclements deleted the PYTHON-4903-typing_overloads branch November 5, 2024 15:47
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