-
-
Notifications
You must be signed in to change notification settings - Fork 132
Open
Labels
@Gentle
Description
functionally this code does what I expect it to (asserts go through) but there is a type error in the signature of Converter.structure, it accepts cl: type[T] and UnionType does not match that
from typing import Literal, Union from dataclasses import dataclass import cattrs @dataclass class Add: t: Literal["ADD"] v: int @dataclass class Sub: t: Literal["SUB"] v: int Op = Union[Add, Sub] Op2 = Add | Sub assert cattrs.structure(dict(t="ADD", v=10), Op) == Add(t="ADD", v=10) assert cattrs.structure(dict(t="SUB", v=5), Op2) == Sub(t="SUB", v=5)
if I change this https://github.com/python-attrs/cattrs/blob/main/src/cattrs/converters.py#L587 to
def structure(self, obj: UnstructuredValue, cl: type[T] | UnionType) -> T:
the type error goes away but I'm not sure if that is the right solution