Skip to content

TypedDict using keywords causes "error: Too many arguments for TypedDict()" #11555

Closed

Description

@lillekemiker

Bug Report

In the typing docs for TypedDict there is an example of defining a TypedDict using keywords mapped to types

Point2D = TypedDict('Point2D', x=int, y=int, label=str)

When running mypy on this exact example, I get the following error:

type_test.py:4: error: Too many arguments for TypedDict()

If using the alternative definition with a positional dictionary, no error.

Point2D = TypedDict('Point2D', {'x': int, 'y': int, 'label': str})

Link to docs:
https://docs.python.org/3/library/typing.html#typing.TypedDict

To Reproduce

  1. Create a file with the above code example and necessary imports
  2. Run mypy on file
  3. Observe error message

Expected Behavior

No error

Actual Behavior

Error.

Your Environment

  • Mypy version used: 0.812 and 0.910 tested
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): ignore_missing_imports=true
  • Python version used: 3.9.2
  • Operating system and version: macOS 11.6

Activity

  1. sobolevn commented on Nov 18, 2021

    @sobolevn
    Member

    Related #11206

    I can work on it after #11206 will be finished. There would be a lot of similar constructs.

  2. 97littleleaf11 commented on Dec 14, 2021

    @97littleleaf11
    Collaborator

    I opened an issue about this. https://bugs.python.org/issue46066.
    I think this syntax is confusing since we have the total keyword.

  3. 97littleleaf11 commented on Dec 15, 2021

    @97littleleaf11
    Collaborator

    #2492 (comment):

    This doesn't seem feasible now that we have the total= keyword argument to TypedDict. Also, TypedDict is officially supported in Python and we want to avoid mypy-specific extensions.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions