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

make_dataclass for Pytree #13

Closed
pablo2909 opened this issue Sep 6, 2023 · 5 comments · Fixed by #14
Closed

make_dataclass for Pytree #13

pablo2909 opened this issue Sep 6, 2023 · 5 comments · Fixed by #14

Comments

@pablo2909
Copy link

Hi,

Thank you for this super cool library.

I was wondering if there is something similar to make_dataclass from dataclasses here ? In my case it would be super useful to build some custom metrics based on a config file.

Thanks again :)

@pablo2909
Copy link
Author

pablo2909 commented Sep 6, 2023

Playing a bit with it, I'm able to do this but I'm not sure this is the way to go:

import dataclasses as dc
from simple_pytree import dataclass, Pytree, static_field

A = dc.make_dataclass('A',
                   [('x', int),
                     'y',
                    ('z', int, static_field(default=5))],
                   )

@dataclass
class B(A, Pytree):
    ...

B(1, 2, 3)

@cgarciae
Copy link
Owner

cgarciae commented Sep 6, 2023

Hey @pablo2909, I think your approach is correct and should be supported. It currently doesn't work but I created #14 fix it.

@cgarciae
Copy link
Owner

cgarciae commented Sep 6, 2023

Fixed in 0.2.2

@pablo2909
Copy link
Author

Thank you for the super quick response and fix :)

Could you please elaborate on what did not work and the fix you brought ? Because the MWE I posted was working for me.

Thanks again ! This library is really super useful :)

@cgarciae
Copy link
Owner

cgarciae commented Sep 6, 2023

No problem! The resulting pytree was not makingz a static field.

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

Successfully merging a pull request may close this issue.

2 participants