cattrs icon indicating copy to clipboard operation
cattrs copied to clipboard

Types of nested generic fields are not specific enough

Open letalvoj opened this issue 3 years ago • 2 comments

  • 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?

letalvoj avatar Nov 15 '21 17:11 letalvoj

It will be the case when I merge https://github.com/python-attrs/cattrs/pull/177 in a few days :)

Tinche avatar Nov 16 '21 02:11 Tinche

Can this be closed now?

Tinche avatar Dec 12 '21 23:12 Tinche