Skip to content

Allow docstrings in Python 3.6+ class based TypedDict #3747

@JakobGM

Description

@JakobGM

At the moment, if you try to define the following type,

from mypy_extensions import TypedDict

class GroupJSON(TypedDict):
    """ JSON representation of group, received from API-endpoint """
    group_name: str

you end up receiving an mypy error saying something along the lines of expected format 'key_name: value_type'. Excuse me for not providing the exact error message, as I won't be able to use a computer for a couple of days.

It can be avoided by using the normal #-comment syntax. It still came as a surprise when using this syntax. Most people are probably used to documenting classes with docstrings.

Perhaps this behaviour is intentional, as TypedDict instances are interpreted as normal dictionaries at runtime? I would still argue that this is an implementation detail leaking through to the interface. Perhaps the docstring can be entirely ignored at runtime?

Thanks in advance,
Jakob

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