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

Register multiple hooks for a class #541

Closed
isohedronpipeline opened this issue May 27, 2024 · 3 comments
Closed

Register multiple hooks for a class #541

isohedronpipeline opened this issue May 27, 2024 · 3 comments

Comments

@isohedronpipeline
Copy link

  • cattrs version: 23.2.3
  • Python version: 3.10.12
  • Operating System: Ubuntu-22.04
  • attrs version: 23.2.0

I mentioned this at the end of another ticket, but I thought it deserved its own issue.

I'd like to register multiple unstructure hooks to a class. Specifically, I want to register subclasses and also omit defaults.

How can I combine this:
include_subclasses(Toy, c, union_strategy=configure_tagged_union)
with this:
hook = make_dict_unstructure_fn(Toy, c, _cattrs_omit_if_default=True)

Thanks :-)

Ben

@Tinche
Copy link
Member

Tinche commented Jun 1, 2024

Hello!

Can you create your converter with Converter(omit_if_default=True)? That's the easiest way. If not we can brainstorm further.

@isohedronpipeline
Copy link
Author

I think so!
Thanks Tin :-)

@Tinche
Copy link
Member

Tinche commented Jun 3, 2024

Alright, closing this to keep the issue list more manageable ;)

@Tinche Tinche closed this as completed Jun 3, 2024
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