Open bilelomrani1 opened 1 year ago
Hello there @bilelomrani1, thanks for posting!
Hmm that's interesting. Does attrs
have an API that is interchangeable with the built-in dataclasses
?
For parser.add_arguments(<attrs.dataclass>, dest="foo")
to work, what we'd need are equivalents to:
dataclasses.fields(dataclass_type_or_instance) -> Iterable[dataclasses.Field]
dataclasses.is_dataclass(dataclass) -> bool
dataclasses.Field
attributes:
str
str | type
Any | dataclasses.MISSING
Callable[[], Any] | dataclasses.MISSING
dict
If there's a way of get this information from the attrs.dataclass
, then yeah, this would be feasible, nice contribution! :)
Hey @bilelomrani1, do you know if attrs
has this kind of interop with dataclasses
?
Hi @lebrice I'm sorry for the long delay. I no longer need this feature as I found an existing alternative for my use case. But I can still provide some answers if you are still interested in this feature, I once wrote a dataclasses/attrs parser some time ago, the code is available here. Looking at it, here is what I used:
attr.fields(attr_type)
: list of attrs
fields, containing the field name, type, factory/default value.attr.has(attr_type) --> bool
: equivalent of dataclasses.is_dataclass(dataclass) -> bool
attrs is a popular third-party package for defining dataclasses with additional convenient features (converters, more fine-grained initialization, etc.). Currently
simple-parsing
only supports native dataclasses, is there any interest to support attrs dataclasses as well?