mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Way to support attributes for TypedDict

Open bilbeyt opened this issue 2 years ago • 0 comments

Bug Report

Currently i am working with a typeddict that is transforming to AttributeDict and i dont have a way to preserve typings. I am implementing a custom plugin for this but the type is only available for get_type_analyze_hook.

To Reproduce

from typing import TypedDict

Test = TypedDict(
    "Test", 
    {
        "from": str,
        "test": str
    }
)

my_test: Test = {
    "from": "lorem",
    "test": "11"
}

my_test.test = "22"

Expected Behavior

There wont be any errors.

Actual Behavior

test.py:17: error: "Test" has no attribute "test"  [attr-defined]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.0.1
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.10.9

bilbeyt avatar Jul 05 '23 09:07 bilbeyt