From 2ff13e4340f263122d429dbf957297b64657222f Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Sun, 26 May 2019 08:21:51 -0400 Subject: [PATCH] Use a loop instead of multiple similar conditionals --- src/pip/_internal/utils/deprecation.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/pip/_internal/utils/deprecation.py b/src/pip/_internal/utils/deprecation.py index ed07eb5f0..b9359bddc 100644 --- a/src/pip/_internal/utils/deprecation.py +++ b/src/pip/_internal/utils/deprecation.py @@ -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) - ) - 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) + 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 + ) # Raise as an error if it has to be removed. if gone_in is not None and parse(current_version) >= parse(gone_in):