Skip to content
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

Docs: Update TypedDict import statements #16958

Merged
merged 4 commits into from
Feb 29, 2024
Merged

Conversation

rdimaio
Copy link
Contributor

@rdimaio rdimaio commented Feb 28, 2024

Since Python 3.8, TypedDict has been available from the typing module.

As Python 3.8+ is needed to use mypy (https://github.com/python/mypy/blob/master/setup.py#L12), then it's best for the docs to reflect Python 3.8+ usage.

For previous versions, there's already a disclaimer on the page that explains that typing_extensions must be used: https://github.com/python/mypy/blob/master/docs/source/typed_dict.rst?plain=1#L102-L110

Since Python 3.8, `TypedDict` has been available from the `typing` module. 

As Python 3.8+ is needed to use mypy (https://github.com/python/mypy/blob/master/setup.py#L12), then it's best for the docs to reflect Python 3.8+ usage.

For previous versions, there's already a disclaimer on the page that explains that `typing_extensions` must be used: https://github.com/python/mypy/blob/master/docs/source/typed_dict.rst?plain=1#L102-L110
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Thanks! Looks like we have a bunch of from typing_extensions import Literal and from typing_extensions import Protocol instances scattered across the docs as well -- want to update those at the same time?

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Thanks! Nearly there

@@ -547,7 +547,7 @@ Correct usage:
.. code-block:: python

# Use "mypy --enable-error-code unimported-reveal"
from typing import reveal_type # or `typing_extensions`
from typing import reveal_type # "from typing_extensions" in Python 3.10 and earlier
Copy link
Member

Choose a reason for hiding this comment

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

I think this one can be left as-is: the existing message is more concise, and isn't incorrect (you can still import it from typing_extensions on 3.11+)

@@ -888,7 +888,7 @@ This produces the following output from mypy:
.. code-block:: text

example.py:3: error: "bool" is invalid as return type for "__exit__" that always returns False
example.py:3: note: Use "typing_extensions.Literal[False]" as the return type or change it to
example.py:3: note: Use "typing.Literal[False]" as the return type or change it to
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 update the error message mypy emits here, but until we do so, we shouldn't change the docs here: this copies exactly the error message mypy emits on the above snippet https://mypy-play.net/?mypy=latest&python=3.12&gist=aab6f1cc25003dd1573cb3d8b8df2396

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Thanks!

@JelleZijlstra JelleZijlstra merged commit 02c50bc into python:master Feb 29, 2024
2 checks passed
@rdimaio rdimaio deleted the patch-1 branch February 29, 2024 15:49
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