Skip to content

Declaring a Optional[TypedDict] fails at runtime #2614

@rowillia

Description

@rowillia

For example, executing the following code results in a stack trace

from typing import Optional

from mypy_extensions import TypedDict

TaggedPoint = TypedDict('TaggedPoint', {'type': str, 'x': int, 'y': int})

def maybe_create_tagged_point() -> Optional[TaggedPoint]:
    return None
Traceback (most recent call last):
  File "test_runtime_typed_dict.py", line 7, in <module>
    def maybe_create_tagged_point() -> Optional[TaggedPoint]:
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/typing.py", line 648, in __getitem__
    return Union[arg, type(None)]
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/typing.py", line 551, in __getitem__
    dict(self.__dict__), parameters, _root=True)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/typing.py", line 511, in __new__
    for t2 in all_params - {t1} if not isinstance(t2, TypeVar)):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/typing.py", line 511, in <genexpr>
    for t2 in all_params - {t1} if not isinstance(t2, TypeVar)):
  File "/Users/rwilliams/src/oss/mypy/venv/src/mypy-extensions/extensions/mypy_extensions.py", line 20, in _check_fails
    raise TypeError('TypedDict does not support instance and class checks')
TypeError: TypedDict does not support instance and class checks

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