KEMBAR78
Docs: Update `TypedDict` import statements by rdimaio · Pull Request #16958 · python/mypy · GitHub
Skip to content

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

# 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+)

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!

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@JelleZijlstra JelleZijlstra merged commit 02c50bc into python:master Feb 29, 2024
@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