Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fields of optional dataclasses are not displayed in the generated help #509

Closed
maticus opened this issue May 23, 2024 · 1 comment
Closed
Labels
duplicate This issue or pull request already exists enhancement New feature or request

Comments

@maticus
Copy link

maticus commented May 23, 2024

🐛 Bug report

Prompted by the super-quick fix of #507 (thanks!) I'm doing some more testing of jsonargparse with nested optional dataclasses, and found out:

Fields of optional dataclasses are not displayed in the generated help

To reproduce

Following script

import jsonargparse
from typing import Optional
from dataclasses import dataclass

@dataclass
class B:
    c: int = 3

@dataclass
class A:
    b: B
    ob: Optional[B]

def fun(a: A):
    print(a)

jsonargparse.CLI(fun)

when ran:
python python-jsonargparse-optional-dataclass.py -h

displays:

...
  -h, --help            Show this help message and exit.
  --config CONFIG       Path to a configuration file.
  --print_config[=flags]
                        Print the configuration after applying all other arguments and exit. The optional flags customizes the output and
                        are one or more keywords separated by comma. The supported flags are: comments, skip_default, skip_null.

A(b: __main__.B, ob: Optional[__main__.B]):
  --a CONFIG            Path to a configuration file.
  --a.ob OB             (type: Optional[B], default: null)

B(c: int = 3):
  --a.b CONFIG          Path to a configuration file.
  --a.b.c C             (type: int, default: 3)

Note, --a.ob.c is missing, but I can configure using this option:

$ python python-jsonargparse-optional-dataclass.py  --a.b.c 77 --a.ob.c 78
A(b=B(c=77), ob=B(c=78))

Expected behavior

The --a.ob.c option should also be displayed in the help.

Environment

  • jsonargparse version: today's master :-) (git-describe: v4.28.0-10-gf44ba32)
  • Python version: 3.10
  • How jsonargparse was installed: pip install -e ".[dev,all]" from checked-out repo.
  • OS: Ubuntu Jammy
@mauvilsa
Copy link
Member

Thank you for reporting! This is actually a feature request duplicate of #368. The proposal is to do as described in #368 (comment), though this hasn't yet been implemented. I will close this issue in favor of the previous one.

@mauvilsa mauvilsa added duplicate This issue or pull request already exists enhancement New feature or request and removed bug Something isn't working labels May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants