Skip to content

PYTHON-3074 Add documentation for type hints #906

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 15 commits into from
Mar 29, 2022

Conversation

blink1073
Copy link
Member

No description provided.

@blink1073 blink1073 marked this pull request as ready for review March 25, 2022 21:06
except TypeError:
if hasattr(value, "__origin__"):
is_mapping = issubclass(value.__origin__, abc.MutableMapping)
if not is_mapping and not issubclass(value, RawBSONDocument):
Copy link
Member

Choose a reason for hiding this comment

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

Should we add a proper test for this fix?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Client Document Type
--------------------

:class:`~pymongo.mongo_client.MongoClient` is generic on the document type used to decode BSON documents.
Copy link
Member

Choose a reason for hiding this comment

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

We should mention that Client/Database/Collection are all generic too. For instance the TypedDict Movie example would probably make more sense at the collection level:

  >>> from pymongo.collection import Collection
  ...
  >>> client: MongoClient[Dict[str, Any]] = MongoClient()
  >>> collection: Collection[Movie] = client.test.movies

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@blink1073 blink1073 requested a review from ShaneHarvey March 28, 2022 22:05
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.

one minor comment.

@@ -309,6 +309,9 @@ def test_son_document_type(self) -> None:
assert retreived is not None
retreived["a"] = 1

def test_son_document_type_runtime(self) -> None:
client = MongoClient(document_class=SON[str, Any])
Copy link
Member

Choose a reason for hiding this comment

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

Add connect=False to avoid starting threads.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

@blink1073 blink1073 requested a review from ShaneHarvey March 28, 2022 22:24

As of version 4.1, PyMongo ships with `type hints`_.

With type hints, Python type checkers can easily find bugs before they reveal themselves in your code. If your IDE is configured to use type hints,
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe put a link here for how to configure type hints in popular IDEs?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@blink1073 blink1073 requested a review from juliusgeo March 29, 2022 11:39
Copy link
Contributor

@juliusgeo juliusgeo left a comment

Choose a reason for hiding this comment

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

LGTM!

@blink1073 blink1073 merged commit 1d30802 into mongodb:master Mar 29, 2022
@blink1073 blink1073 deleted the PYTHON-3074 branch March 29, 2022 23:03
juliusgeo pushed a commit to juliusgeo/mongo-python-driver that referenced this pull request Apr 7, 2022
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