-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
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
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.
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?
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.
Thanks! Nearly there
docs/source/error_code_list2.rst
Outdated
@@ -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 |
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 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
@@ -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 |
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.
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
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.
Thanks!
Co-authored-by: Alex Waygood <[email protected]>
Since Python 3.8,
TypedDict
has been available from thetyping
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