1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
"""Tests for PEP 649 (Deferred Evaluation Of Annotations Using Descriptors)."""
from __future__ import annotations
from typing import Generic, TypeVar
from attrs import define
from cattrs import Converter
T = TypeVar("T")
@define
class GenericClass(Generic[T]):
t: T
def test_generics_with_stringified_annotations():
"""Type resolution works with stringified annotations."""
converter = Converter()
inst = GenericClass(42)
dct = converter.unstructure(inst, unstructure_as=GenericClass[int])
assert dct == {"t": 42}
assert converter.structure(dct, GenericClass[int])
|