Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
Docs: UpdateTypedDict import statements#16958
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
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 left a comment
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 offrom typing_extensions import Literal andfrom typing_extensions import Protocol instances scattered across the docs as well -- want to update those at the same time?
AlexWaygood left a comment
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
| # Use "mypy --enable-error-code unimported-reveal" | ||
| from typingimport reveal_type#or `typing_extensions` | ||
| from typingimport reveal_type#"fromtyping_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 fromtyping_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 |
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 snippethttps://mypy-play.net/?mypy=latest&python=3.12&gist=aab6f1cc25003dd1573cb3d8b8df2396
AlexWaygood left a comment
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!
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
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