Skip to content

Deprecate mypy_extensions.TypedDict? #46

Closed

Description

@AlexWaygood

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?

Activity

  1. JelleZijlstra commented on Aug 17, 2023

    @JelleZijlstra
    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
  2. AlexWaygood commented on Aug 17, 2023

    @AlexWaygood
    MemberAuthor

    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__

  3. AlexWaygood commented on Aug 17, 2023

    @AlexWaygood
    MemberAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions