# Buggy code
def expand_default(self, option):
    default_value = None
    if self.parser is not None:
        self.parser._update_defaults(self.parser.defaults)
        default_value = 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)
        )

    return help_text


# Traceback (AttributeError)
$ pip install --help
Traceback (most recent call last):
File "/Users/rblanchard/repos/invitae-evidence-service/ve/bin/pip", line 8, in <module>
sys.exit(main())
File "/Users/rblanchard/repos/invitae-evidence-service/ve/lib/python3.7/site-packages/pip/_internal/cli/main.py", line 75, in main
return command.main(cmd_args)
File "/Users/rblanchard/repos/invitae-evidence-service/ve/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 117, in main
return self._main(args)
File "/Users/rblanchard/repos/invitae-evidence-service/ve/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 131, in _main
options, args = self.parse_args(args)
File "/Users/rblanchard/repos/invitae-evidence-service/ve/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 111, in parse_args
return self.parser.parse_args(args)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 1387, in parse_args
stop = self._process_args(largs, rargs, values)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 1427, in _process_args
self._process_long_opt(rargs, values)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 1501, in _process_long_opt
option.process(opt, value, values, self)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 785, in process
self.action, self.dest, opt, value, values, parser)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 807, in take_action
parser.print_help()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 1647, in print_help
file.write(self.format_help())
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 1635, in format_help
result.append(self.format_option_help(formatter))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 1618, in format_option_help
result.append(group.format_help(formatter))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 1101, in format_help
result += OptionContainer.format_help(self, formatter)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 1072, in format_help
result.append(self.format_option_help(formatter))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 1061, in format_option_help
result.append(formatter.format_option(option))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 322, in format_option
help_text = self.expand_default(option)
File "/Users/rblanchard/repos/invitae-evidence-service/ve/lib/python3.7/site-packages/pip/_internal/cli/parser.py", line 123, in expand_default
default_value, redact_auth_from_url(default_value))
File "/Users/rblanchard/repos/invitae-evidence-service/ve/lib/python3.7/site-packages/pip/_internal/utils/misc.py", line 826, in redact_auth_from_url
return _transform_url(url, _redact_netloc)[0]
File "/Users/rblanchard/repos/invitae-evidence-service/ve/lib/python3.7/site-packages/pip/_internal/utils/misc.py", line 786, in _transform_url
purl = urllib_parse.urlsplit(url)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/parse.py", line 418, in urlsplit
url, scheme, _coerce_result = _coerce_args(url, scheme)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/parse.py", line 123, in _coerce_args
return _decode_args(args) + (_encode_result,)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/parse.py", line 107, in _decode_args
return tuple(x.decode(encoding, errors) if x else '' for x in args)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/parse.py", line 107, in <genexpr>
return tuple(x.decode(encoding, errors) if x else '' for x in args)
AttributeError: 'list' object has no attribute 'decode'

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

    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