Skip to content

Commit

Permalink
Handle case of list default values in UpdatingDefaultsHelpFormatter
Browse files Browse the repository at this point in the history
Happens because we pass a list from --extra-index-url
  • Loading branch information
Noah Gorny committed Dec 4, 2020
1 parent 8bc9c33 commit 5cfd8a7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions news/9191.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Handle case of list default values in UpdatingDefaultsHelpFormatter
Happens because we pass a list from --extra-index-url
18 changes: 13 additions & 5 deletions src/pip/_internal/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,23 @@ class UpdatingDefaultsHelpFormatter(PrettyHelpFormatter):
"""

def expand_default(self, option):
default_value = None
default_values = None
if self.parser is not None:
self.parser._update_defaults(self.parser.defaults)
default_value = self.parser.defaults.get(option.dest)
default_values = self.parser.defaults.get(option.dest)
help_text = optparse.IndentedHelpFormatter.expand_default(self, option)

if default_value and option.metavar == 'URL':
help_text = help_text.replace(
default_value, redact_auth_from_url(default_value))
if default_values and option.metavar == 'URL':
if isinstance(default_values, string_types):
default_values = [default_values]

# If its not a list, we should abort and just return the help text
if not isinstance(default_values, list):
default_values = []

for val in default_values:
help_text = help_text.replace(
val, redact_auth_from_url(val))

return help_text

Expand Down

0 comments on commit 5cfd8a7

Please sign in to comment.