lebrice / SimpleParsing

Simple, Elegant, Typed Argument Parsing with argparse
MIT License
409 stars 51 forks source link

Default not displayed in the help text when no description comment exists #64

Closed rggjan closed 2 years ago

rggjan commented 3 years ago

This example:

from dataclasses import dataclass

from simple_parsing import ArgumentParser

parser = ArgumentParser()

@dataclass
class Options:
    """These are the options"""

    foo: str = "aaa"  # Description
    bar: str = "bbb"

parser.add_arguments(Options, dest="options")

args = parser.parse_args(["--help"])

outputs:

usage: scratch.py [-h] [--foo str] [--bar str]

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

Options ['options']:
  These are the options

  --foo str   Description (default: aaa)
  --bar str

Why is the default value displayed for foo, but not for bar? Even when no description comment is given, it would be useful to know the default value set, I would think?

lebrice commented 3 years ago

Hi @rggjan , interesting issue, thanks for posting!

This might have to to do with how the ArgumentDefaultsHelpFormatter from argparse works, or maybe I'm doing something wrong in one of these places:

I'll setup a quick test for this and get back to you! Thanks again for posting!

lebrice commented 2 years ago

Reopening this, the fix doesn't work seem to work anymore for python 3.9.12 and above.