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

Structure doesn't work with sub-classes #360

Closed
ares-b opened this issue May 2, 2023 · 1 comment
Closed

Structure doesn't work with sub-classes #360

ares-b opened this issue May 2, 2023 · 1 comment

Comments

@ares-b
Copy link

ares-b commented May 2, 2023

  • cattrs version:
  • Python version:
  • Operating System:

Description

Cattrs cannot structure My Class if one of my attributes type is a Parent Type of other Child types.

What I Did

import attrs
import cattrs

@attrs.define
class A:
    pass

@attrs.define
class B(A):
    z: float = attrs.field(validator=attrs.validators.instance_of(float))

@attrs.define
class MyClass:
    test: A = attrs.field(validator=attrs.validators.instance_of(A))

mbis = cattrs.structure({"test":  {"z": 3.0}}, MyClass)
# mbis = MyClass(test=A())
# should be MyClass(test=B(z=3.0))
@Tinche
Copy link
Member

Tinche commented May 2, 2023

You might want to keep an eye on #312, I think that's what you're after.

@Tinche Tinche closed this as completed May 2, 2023
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