ericvsmith / dataclasses

Apache License 2.0
587 stars 53 forks source link

Add tests for generic dataclasses #54

Closed ilevkivskyi closed 6 years ago

ilevkivskyi commented 7 years ago

I think it makes sense to add tests that check that dataclasses interact nicely with typing.Generic and type variables. Most likely no changes is needed to the code (only tests) since we use a decorator @dataclass. But still Generic uses a complex metaclass (this will be removed if/when PEP 560 is accepted and replaced with __init_subclass__ and new friends).

I think it makes sense to add tests checking that things like this work:

@dataclass
class LabeledBox(Generic[T]):
    content: T
    label: str = '<unknown>'

box = LabeledBox(42)
assert box.content == 42
assert box.label == '<unknown>'

boxes: List[LabeledBox[int]] = []  # subscripting the resulting class should work, etc.