Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types of nested generic fields are not specific enough #185

Open
letalvoj opened this issue Nov 15, 2021 · 2 comments
Open

Types of nested generic fields are not specific enough #185

letalvoj opened this issue Nov 15, 2021 · 2 comments

Comments

@letalvoj
Copy link

letalvoj commented Nov 15, 2021

  • 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 letalvoj changed the title Custom generic unstructure hooks Types of nested generic fields are not specific enough Nov 15, 2021
@Tinche
Copy link
Member

Tinche commented Nov 16, 2021

It will be the case when I merge #177 in a few days :)

@Tinche
Copy link
Member

Tinche commented Dec 12, 2021

Can this be closed now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants