FelixTheC / strongtyping

Decorator which checks whether the function is called with the correct type of parameters.
https://pypi.org/project/strongtyping/
107 stars 3 forks source link

Handle functions wich specify a value having of type TypeDict #69

Closed FelixTheC closed 3 years ago

FelixTheC commented 3 years ago

Describe the bug

class UserSelectedComponent(TypedDict):
    id: uuid.UUID
    min_concentration: float
    max_concentration: float

@match_typing
def validate_selected_component_entry(value: UserSelectedComponent):
    pass

calling now the function validate_selected_component_entry will lead to

    return supported_typings[f"checking_typing_{origin_name}"](
KeyError: 'checking_typing_typeddict'
FelixTheC commented 3 years ago

The current workaround is to decorate the TypedDict class with match_class_typing And to do the following.

@match_class_typing
class UserSelectedComponent(TypedDict):
    id: uuid.UUID
    min_concentration: float
    max_concentration: float

@match_typing
def validate_selected_component_entry(value: dict):
    UserSelectedComponent(value)

this will give the expected output.

FelixTheC commented 3 years ago

Bugfix was merged into main and will be available in the next release. v2.1.7