davidfstr / trycast

trycast parses JSON-like values whose shape is defined by TypedDicts and other standard Python type hints.

Home Page:https://dafoster.net/projects/trycast/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Recognize generic TypedDicts, like Point[int]

davidfstr opened this issue · comments

Python 3.11 added support for generic TypedDicts.

For example, the following generic TypedDict can (probably) be defined now:

T = TypeVar('T', bound=Union[int, float, complex])

class Point(TypedDict, Generic[T]):
    x: T
    y: T

int_point: Point[int] = {"x": 1, "y": 2}
float_point: Point[float] = {"x": 1.0, "y": 2.0}
complex_point: Point[complex] = {"x": 1j, "y": 2j}

It would be nice if trycast() recognized parameterized TypedDict types like Point[int]