lebrice / SimpleParsing

Simple, Elegant, Typed Argument Parsing with argparse
MIT License
399 stars 49 forks source link

Missing descriptions with multiple inheritance #162

Closed justin-together closed 1 year ago

justin-together commented 1 year ago

Describe the bug

Some argument descriptions are missing when using multiple inheritance.

To Reproduce

from simple_parsing import ArgumentParser
from dataclasses import dataclass

@dataclass
class Foo:
   bar: int = 123  #: The bar property

@dataclass
class Baz:
   bat: int = 123  #: The bat property

@dataclass
class FooBaz(Foo, Baz):
   foobaz: int = 123  #: The foobaz property

if __name__ == "__main__":
   parser = ArgumentParser()
   parser.add_arguments(FooBaz, "foobaz")
   args = parser.parse_args()
   foobaz: FooBaz = args.foobaz
   print(foobaz)

Expected behavior The help string for "bat" contains "The bat property".

Actual behavior The help string for "bat" is empty.

usage: foo.py [-h] [--bat int] [--bar int] [--foobaz int]

optional arguments:
  -h, --help    show this help message and exit

FooBaz ['foobaz']:
  FooBaz(bat: int = 123, bar: int = 123, foobaz: int = 123)

  --bat int     (default: 123)
  --bar int     : The bar property (default: 123)
  --foobaz int  : The foobaz property (default: 123)

Desktop (please complete the following information):

Additional context None.

lebrice commented 1 year ago

Ooh, that's a really cute bug! Thanks @justin-together , good catch! This is probably a bug in this function: https://github.com/lebrice/SimpleParsing/blob/6fca2e9322f73af7fca0e39978619b1286438def/simple_parsing/docstring.py#L21-L34

Would you be interested in taking a look at it yourself, by any chance? :) If not, no worries, I can add this to my stack of todos as well.

Thanks for pointing this out!