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

Deprecate mypy_extensions.TypedDict? #46

Closed
AlexWaygood opened this issue Aug 17, 2023 · 3 comments · Fixed by #47
Closed

Deprecate mypy_extensions.TypedDict? #46

AlexWaygood opened this issue Aug 17, 2023 · 3 comments · Fixed by #47

Comments

@AlexWaygood
Copy link
Member

mypy_extensions.TypedDict is problematic for several reasons:

  • mypy_extensions.TypedDict is missing quite a few features that have been added to typing.TypedDict at runtime (and have been backported to typing_extensions.TypedDict).
  • I think the existence of both mypy_extensions.TypedDict and typing_extensions.TypedDict has the potential to be pretty confusing for users.
  • It's quite annoying and error-prone that at typeshed, we have to remember to keep typing._TypedDict, typing_extensions._TypedDict and mypy_extensions._TypedDict all in sync. Unfortunately, we can't put them all in _typeshed and have all three modules import _TypedDict from _typeshed, as the three classes all have slightly subtle differences. (E.g. mypy_extensions._TypedDict doesn't have the __required_keys__ and __optional_keys__ ClassVars that both typing._TypedDict and typing_extensions._TypedDict have.)
  • Mypy now maintains its own copy of the mypy-extensions stubs anyway, so its stubs for mypy_extensions are no longer automatically updated with each typeshed sync. That means that even if we update the stubs for mypy_extensions.TypedDict in typeshed (as we did in Improve __(r)or__ signatures for TypedDict classes typeshed#10565), those updates are no longer of any benefit to mypy users unless mypy maintainers remember to copy across the changes to their forked version of the mypy_extensions stubs.

I propose that we deprecate mypy_extensions.TypedDict, and steer people towards typing_extensions.TypedDict instead: it's up-to-date with the features on typing.TypedDict, it's much more comprehensively tested, and it has up-to-date stubs.

Thoughts?

@JelleZijlstra
Copy link
Member

Agree, there's no need for mypy_extensions.TypedDict any more. As an implementation strategy, we can:

  • Raise a runtime DeprecationWarning when a new mypy_extensions.TypedDict class is created
  • Have mypy show a warning whenever mypy_extensions.TypedDict is used

@AlexWaygood
Copy link
Member Author

I'm taking a look at the runtime side of things. One issue: it seems we'd really need stacklevel=3 if you're constructing a TypedDict class like this:

Foo = TypedDict('Foo', {'x': int})

...But you'd need stacklevel=2 if you're constructing a TypedDict like this:

class Bar(TypedDict):
    x: int

I'm not sure if there's a way to distinguish between the two, if we emit the DeprecationWarning in _TypedDictMeta.__new__

@AlexWaygood
Copy link
Member Author

I'm not sure if there's a way to distinguish between the two, if we emit the DeprecationWarning in _TypedDictMeta.__new__

Hmm, I think I have a solution

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 a pull request may close this issue.

2 participants