Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

TypedDict's totality flag not correctly interpreted when inhering from another TypedDict #204

@kkom

Description

@kkom

Hey, I have a behaviour which I think is a bug / missing functionality.

Here is the code (using typedload==2.7):

from typing import Optional, TypedDict

import typedload

class ExampleTypedDict(TypedDict):
    a: int
    b: Optional[int]

d = {"a": 0}

print(f"{d=}")

td = ExampleTypedDict(**d)

print(f"{td=}")

tdl = typedload.load(d, ExampleTypedDict)

And here is the result of running it:

optional_typeddict pipenv run python main.py    
d={'a': 0}
td={'a': 0}
Traceback (most recent call last):
  File "/Users/kkom/Desktop/optional_typeddict/main.py", line 17, in <module>
    tdl = typedload.load(d, ExampleTypedDict)
  File "/Users/kkom/.local/share/virtualenvs/optional_typeddict-hmzsbyx_/lib/python3.9/site-packages/typedload/__init__.py", line 200, in load
    return loader.load(value, type_)
  File "/Users/kkom/.local/share/virtualenvs/optional_typeddict-hmzsbyx_/lib/python3.9/site-packages/typedload/dataloader.py", line 294, in load
    raise e
  File "/Users/kkom/.local/share/virtualenvs/optional_typeddict-hmzsbyx_/lib/python3.9/site-packages/typedload/dataloader.py", line 290, in load
    return cast(T, func(self, value, type_))
  File "/Users/kkom/.local/share/virtualenvs/optional_typeddict-hmzsbyx_/lib/python3.9/site-packages/typedload/dataloader.py", line 500, in _namedtupleload
    raise TypedloadValueError(
typedload.exceptions.TypedloadValueError: Value does not contain fields: {'b'} which are necessary for type ExampleTypedDict
Path: .

PS: Here is my exact setup:

➜  optional_typeddict cat Pipfile                  
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
typedload = "==2.7"

[dev-packages]

[requires]
python_version = "3.9"

CC: @sid-at-github

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