Use a loop instead of multiple similar conditionals
@@ -80,17 +80,18 @@ def deprecated(reason, replacement, gone_in, issue=None):
# Construct a nice message.
# This is eagerly formatted as we want it to get logged as if someone
# typed this entire message out.
- message = DEPRECATION_MSG_PREFIX + reason
-
- if gone_in is not None:
- message += (
- " pip {} will remove support for this functionality".format(gone_in)
+ sentences = [
+ (reason, DEPRECATION_MSG_PREFIX + "{}"),
+ (gone_in, "pip {} will remove support for this functionality."),
+ (replacement, "A possible replacement is {}."),
+ (issue, (
+ "You can find discussion regarding this at "
+ "https://github.com/pypa/pip/issues/{}."
+ )),
+ ]
+ message = " ".join(
+ template.format(val) for val, template in sentences if val is not None
)
- if replacement is not None:
- message += " A possible replacement is {}.".format(replacement)
- if issue is not None:
- url = "https://github.com/pypa/pip/issues/" + str(issue)
- message += " You can find discussion regarding this at {}.".format(url)
# Raise as an error if it has to be removed.
if gone_in is not None and parse(current_version) >= parse(gone_in):
