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

Class title is not the name of the class but a string representation of it. #605

Open
eldadcool opened this issue Oct 27, 2024 · 3 comments
Labels
refactor Improvements to the quality of the code

Comments

@eldadcool
Copy link

🐛 Bug report

The title of a class added using "add_class_arguments" is printed as str(TestClass) instead of TestClass.__name__ as expected.
This lead to the title be: "<class 'main.TestClass'>" instead of "TestClass"

To reproduce

from jsonargparse import ArgumentParser

class TestClass:
    def __init__(self, test_field: int = 5):
        pass

parser = ArgumentParser()
parser.add_class_arguments(TestClass)
parser.print_help()

The result is:

usage: [-h] [--test_field TEST_FIELD]

options:
  -h, --help            Show this help message and exit.

<class '__main__.TestClass'>:
  --test_field TEST_FIELD
                        (type: int, default: 5)

Expected behavior

usage: [-h] [--test_field TEST_FIELD]

options:
  -h, --help            Show this help message and exit.

TestClass:
  --test_field TEST_FIELD
                        (type: int, default: 5)

Environment

  • jsonargparse version: 4.33.2
  • Python version: 3.10.12
  • How jsonargparse was installed: pip install jsonargparse
  • OS: wsl2
@eldadcool eldadcool added the bug Something isn't working label Oct 27, 2024
@mauvilsa
Copy link
Member

mauvilsa commented Oct 28, 2024

Thank you for reporting! Actually this was implemented explicitly like this. The idea was more that people would add docstrings to their classes and functions. But sure, it could be changed to not be a raw str conversion. Though, if changed, I would say it should be a short phrase instead of just the class name, e.g. f"Options for {function_or_class.__name__}".

@mauvilsa mauvilsa added refactor Improvements to the quality of the code and removed bug Something isn't working labels Oct 28, 2024
@mauvilsa
Copy link
Member

@eldadcool would you be interested in contributing the change?

@eldadcool
Copy link
Author

Sure, I will create a pull request as soon as I will have time to work on it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Improvements to the quality of the code
Projects
None yet
Development

No branches or pull requests

2 participants