Skip to content

TypedDict with total=False does not allow clear #12732

Closed as not planned
Closed as not planned
@haroldmeerwaldt

Description

@haroldmeerwaldt

Bug Report

I made a TypedDict with total=False . Then I wanted to clear it, but I got an [attr-defined] error. I can do pop, so I would expect to be able to do clear as well.

To Reproduce

from typing import TypedDict


class MyTypedDict(TypedDict, total=False):
    param1: int
    param2: str

td: MyTypedDict = {"param1": 2, "param2": "foo"}
td.pop("param1")
td.clear()

Actual Behavior

I got

scratch_37.py:10: error: "MyTypedDict" has no attribute "clear"  [attr-defined]

Your Environment

  • Mypy version used: 0.950
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files):
# The following options are set by the --strict command line flag
warn_unused_configs=True
disallow_any_generics=True
disallow_subclassing_any=True
disallow_untyped_calls=True
disallow_untyped_defs=True
disallow_incomplete_defs=True
check_untyped_defs=True
disallow_untyped_decorators=True
no_implicit_optional=True
warn_redundant_casts=True
warn_unused_ignores=True
warn_return_any=True
no_implicit_reexport=True
strict_equality=True
# End of --strict options

ignore_missing_imports=True
show_error_codes=True

plugins=pydantic.mypy, numpy.typing.mypy_plugin
  • Python version used: 3.9.9
  • Operating system and version: Windows 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions