lebrice / SimpleParsing

Simple, Elegant, Typed Argument Parsing with argparse
MIT License
384 stars 46 forks source link

Support for attrs dataclasses #261

Open bilelomrani1 opened 1 year ago

bilelomrani1 commented 1 year ago

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?

lebrice commented 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:

If there's a way of get this information from the attrs.dataclass, then yeah, this would be feasible, nice contribution! :)

lebrice commented 10 months ago

Hey @bilelomrani1, do you know if attrs has this kind of interop with dataclasses ?

bilelomrani1 commented 10 months ago

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: