cattrs
cattrs copied to clipboard
Types of nested generic fields are not specific enough
- cattrs version: 1.8.0
- Python version: 3.9.7
- Operating System: macOS
Description
Let's have the following test case
@define
class X(Generic[T]):
field: List[T]
def pred(cls):
print(f">>> {cls}")
return False
result = X[int]([1, 2, 3])
data = asdict(result)
c = GenConverter()
c.register_unstructure_hook_factory(pred, lambda cls: lambda obj: None)
c.unstructure(result, X[int])
assert c.structure(data, X[int]) == result
it passes, yet it prints
>>> tests.test_generics.test_karel.<locals>.X[int]
>>> typing.List[~T]
>>> ~T
Should it not be the case that the nested fields types (such as List[~T]) are provided with the type resolved, similarly to how the X[int] is provided in its most specific form?
It will be the case when I merge https://github.com/python-attrs/cattrs/pull/177 in a few days :)
Can this be closed now?