Docs: Update TypedDict import statements#16958
Merged
JelleZijlstra merged 4 commits intopython:masterfrom Feb 29, 2024
Merged
Conversation
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
AlexWaygood
reviewed
Feb 28, 2024
Member
AlexWaygood
left a comment
There was a problem hiding this comment.
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?
AlexWaygood
reviewed
Feb 29, 2024
docs/source/error_code_list2.rst
Outdated
|
|
||
| # 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 |
Member
There was a problem hiding this comment.
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+)
docs/source/error_code_list.rst
Outdated
|
|
||
| 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 |
Member
There was a problem hiding this comment.
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
AlexWaygood
reviewed
Feb 29, 2024
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since Python 3.8,
TypedDicthas been available from thetypingmodule.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_extensionsmust be used: https://github.com/python/mypy/blob/master/docs/source/typed_dict.rst?plain=1#L102-L110