You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to the documentation, include_subclasses() supports both attrs and dataclasses. However, when I change the example to use dataclasses, I get an error:
Traceback (most recent call last):
File "/home/eltoder/dev/scratch/cattrs_dc.py", line 14, in <module>
include_subclasses(Parent, converter)
File "/home/eltoder/.local/share/ext-python/python-3.9.16.146/lib/python3.9/site-packages/cattrs/strategies/_subclasses.py", line 73, in include_subclasses
_include_subclasses_without_union_strategy(
File "/home/eltoder/.local/share/ext-python/python-3.9.16.146/lib/python3.9/site-packages/cattrs/strategies/_subclasses.py", line 111, in _include_subclasses_without_union_strategy
dis_fn = converter._get_dis_func(subclass_union)
File "/home/eltoder/.local/share/ext-python/python-3.9.16.146/lib/python3.9/site-packages/cattrs/converters.py", line 756, in _get_dis_func
return create_uniq_field_dis_func(*union_types)
File "/home/eltoder/.local/share/ext-python/python-3.9.16.146/lib/python3.9/site-packages/cattrs/disambiguators.py", line 20, in create_uniq_field_dis_func
cls_and_attrs = [
File "/home/eltoder/.local/share/ext-python/python-3.9.16.146/lib/python3.9/site-packages/cattrs/disambiguators.py", line 21, in <listcomp>
(cl, set(at.name for at in fields(get_origin(cl) or cl))) for cl in classes
File "/home/eltoder/.local/share/ext-python/python-3.9.16.146/lib/python3.9/site-packages/attr/_make.py", line 1944, in fields
raise NotAnAttrsClassError(f"{cls!r} is not an attrs-decorated class.")
attr.exceptions.NotAnAttrsClassError: <class '__main__.Child'> is not an attrs-decorated class.
Additionally, when union_strategy=configure_tagged_union is used, it would be nice to avoid using __subclasses__ so that new classes can be added dynamically. Let me know if you want me to open a separate issue for this.
The text was updated successfully, but these errors were encountered:
Ah, yeah. The easiest fix here would be to just support dataclasses for the default disambiguator. I think it's an easy and useful change. But not in the next release, since it's getting bloated already.
As for the other issue, feel free to open a new ticket and we can triage it.
Description
According to the documentation, include_subclasses() supports both attrs and dataclasses. However, when I change the example to use dataclasses, I get an error:
produces
It does work if I use
union_strategy
:Additionally, when
union_strategy=configure_tagged_union
is used, it would be nice to avoid using__subclasses__
so that new classes can be added dynamically. Let me know if you want me to open a separate issue for this.The text was updated successfully, but these errors were encountered: