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

default values should be visible in help screen #184

Open
dbieber opened this issue Aug 5, 2019 · 11 comments
Open

default values should be visible in help screen #184

dbieber opened this issue Aug 5, 2019 · 11 comments

Comments

@dbieber
Copy link
Member

dbieber commented Aug 5, 2019

As per #114 the default value for an argument should be visible in the help screen.

Some considerations:

  • If the default value is a simple type and not too long in length, we can just show it.
  • If it doesn't serialize well (either because there's no good way to serialize it, or because its serialization is too long to show comfortably), then we need to determine a clean alternative to showing the default. Using the type may be one option for this alternative.
@ntjess
Copy link

ntjess commented Apr 1, 2020

Would showing type information also fit under this issue? E.g. if my function signature is
def main(noDefault: str, default=True)

intuitively I would expect the --help text to show noDefault is a string type. I also suspect this information wouldn't be needed for default arguments, since their type is inferred by the default. Unless its a Union[bool, SomethingElse]...

Should I submit a separate issue for this?

@dbieber
Copy link
Member Author

dbieber commented Apr 1, 2020

Yeah, good idea, let's make a new issue to track that. We might end up fixing them together though.

@ntjess
Copy link

ntjess commented Apr 1, 2020

Agreed. I just created #239. Does it look acceptable?

@dbieber
Copy link
Member Author

dbieber commented Apr 1, 2020

Thanks! Looks great

@MichaelCG8
Copy link
Contributor

MichaelCG8 commented Apr 23, 2020

Hi, I'm exploring fire for the first time and up for having a go at this one. Could you point me towards the best place in the code to start familiarizing my self with the help strings?

EDIT:
Aha, ./fire/helptext.py, the obvious suspect.

@dbieber
Copy link
Member Author

dbieber commented Apr 23, 2020

Glad you found it :)
If you have further questions, don't hesitate to ask.

@MichaelCG8
Copy link
Contributor

MichaelCG8 commented Apr 25, 2020

Okay, so it looks like the target section is _ArgsAndFlagsSection(), which calls _CreateFlagItem(), both in helptext.py

At the moment _CreateFlagItem() takes a docstring_info argument to include the docstring description of the argument in the help text. I propose also passing in the spec variable that is present in _ArgsAndFlagsSection(), which is an instance of fire.inspectutils.FullArgSpec. That contains defaults information, and also type information. My intention is to look into type information after this feature is complete (issue #239), so whichever approach is taken being compatible with that is a plus. As you mention above, I might put them both in at the same time.

I need to dive a bit deeper into which information is included in FullArgSpec in the different python versions.

I'll create the branch issue-184-default-values-should-be-visible-in-help-screen and start working in there. In terms of code style, I presume I should be following the guide here http://google.github.io/styleguide/pyguide.html . Additionally, from looking at the code I'm seeing

  • An indent of 2 spaces
  • PascalCase for function names
  • Redundant parentheses around tuples in return statements (this actually contradicts that style guide section 3.3)
  • No use of type hints (presumably for compatibility with pre PY3.5)

Anything else I should be aware of? Running the rest suite? Shall I stick this info into ./contributing.md while I'm at it?

@MichaelCG8
Copy link
Contributor

Hi, I have a solution ready and would like to create a pull request. However, when I try to push my branch I get the error message:
remote: Permission to google/python-fire.git denied to MichaelCG8.
fatal: unable to access 'https://github.com/google/python-fire.git/': The requested URL returned error: 403

Do I need to be an approved pusher? Or is it preferable that I fork the project and open a pull request from there?

@dbieber
Copy link
Member Author

dbieber commented Apr 26, 2020

#184 (comment): "from looking at the code I'm seeing..."

Awesome summary.

Your assessment of the coding style is spot on. The redundant parentheses is a mistake on our part though, but we can clean that up in a separate change; let's stay consistent for now.

Shall I stick this info into ./contributing.md while I'm at it?

If you're inclined to do so that would be helpful, but keep it in a separate PR so we don't block #184 on getting contributing.md right.

#184 (comment): "Or is it preferable that I fork the project and open a pull request from there?"

Yes, that's the preferred method.
Thanks for putting together the fix!

@MichaelCG8
Copy link
Contributor

Great, thanks. I've put in pull request #251.

@costincaraivan
Copy link

Hi, @dbieber is there a plan to release this somewhat soon? It's a really useful feature 👍 (thanks a lot @MichaelCG8)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants