Skip to content

Types of nested generic fields are not specific enough #185

@letalvoj

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions