-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Hide default value when show_default is False #2509
Hide default value when show_default is False #2509
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, thanks for the contributaion!
This PR makes sense to me. I added some minor comments about the PR.
After fixing those, I could merge it.
src/click/core.py
Outdated
@@ -2865,6 +2865,7 @@ def prompt_for_value(self, ctx: Context) -> t.Any: | |||
show_choices=self.show_choices, | |||
confirmation_prompt=self.confirmation_prompt, | |||
value_proc=lambda x: self.process_value(ctx, x), | |||
show_default=(False if self.show_default is False else True), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not simply: show_default=self.show_default
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this class, self.show_default
is a Union[bool, str, None]
, but termui.prompt
accepts only bool
. Passing through show_default directly gives a type error, and also appears to do the wrong things for values of type filenam
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Thanks for the explanation.
Would you mind writing it down as a comment in the code? I think it would help others who read this line of code for the first time.
tests/test_termui.py
Outdated
@@ -446,3 +446,13 @@ def cli(password): | |||
|
|||
if prompt == "Confirm Password": | |||
assert "Confirm Password: " in result.output | |||
|
|||
|
|||
def test_show_default_false_hides_prompt(runner): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test name can be clearer in order to explain what does this test check.
Mybe something like "test_false_show_default_cause_no_default_display_in_prompt".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for minding my review.
I added two more small suggestions. After you respond to those, we could merge this PR.
src/click/core.py
Outdated
@@ -2865,6 +2865,7 @@ def prompt_for_value(self, ctx: Context) -> t.Any: | |||
show_choices=self.show_choices, | |||
confirmation_prompt=self.confirmation_prompt, | |||
value_proc=lambda x: self.process_value(ctx, x), | |||
show_default=(False if self.show_default is False else True), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Thanks for the explanation.
Would you mind writing it down as a comment in the code? I think it would help others who read this line of code for the first time.
Also, this PR doesn't pass pre-commit at the moment. You might want to run |
Issues fixed. Added comment and also restructured code to make behavior of |
fb3c456
to
3fb7d3d
Compare
Previously, when
show_default
was False on anOption
, the value could still appear in the prompt. Remove this so that sensitive values can be hidden from prompts.Checklist:
CHANGES.rst
summarizing the change and linking to the issue... versionchanged::
entries in any relevant code docs.pre-commit
hooks and fix any issues.pytest
andtox
, no tests failed.