Use a loop instead of multiple similar conditionals

This commit is contained in:
Pradyun Gedam 2019-05-26 08:21:51 -04:00
parent bf728499be
commit 2ff13e4340
No known key found for this signature in database
GPG Key ID: DA17C4B29CB32E4B
1 changed files with 12 additions and 11 deletions

View File

@ -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):