-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-3737 Use __future__ annotations for forward reference type hints #1234
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, thanks! I think the test file changes are fine.
@@ -96,7 +97,7 @@ class ChangeStream(Generic[_DocumentType]): | |||
def __init__( | |||
self, | |||
target: Union[ | |||
"MongoClient[_DocumentType]", "Database[_DocumentType]", "Collection[_DocumentType]" |
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.
Is this allowed even though the MongoClient import is under if TYPE_CHECKING:
?
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.
Yes, because it is converted to a string before it is interpreted.
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.
Neat!
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 with one ask
@@ -2000,10 +2001,10 @@ def get_default_database( | |||
def get_database( | |||
self, | |||
name: Optional[str] = None, | |||
codec_options: Optional["bson.CodecOptions[_DocumentTypeArg]"] = None, | |||
codec_options: Optional[bson.CodecOptions[_DocumentTypeArg]] = None, |
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.
I notice that bson.CodecOptions doesn't render as a link: https://pymongo.readthedocs.io/en/latest/api/pymongo/mongo_client.html#pymongo.mongo_client.MongoClient.get_database
Could you open a new ticket to address that?
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.
The issue being that bson.CodecOptions doesn't render as a type in the docs, right?
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.
Right. Not immediately obvious why it doesn't render.
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.
Might be related to https://jira.mongodb.org/browse/PYTHON-3604
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.
The
test/test_comment.py
changes are due to__future__
annotations explicitly not evaluating all type annotations, causing the test to fail due to comparing the string"Optional[Any]"
to the evaluated valueUnion[Any, None]
. If we want to keep the original, evaluated comparison, we could explicitly evaluate the type annotation as described here: https://docs.python.org/3/library/typing.html#typing.get_type_hints.