Skip to content

Commit

Permalink
Use a loop instead of multiple similar conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyunsg committed May 27, 2019
1 parent bf72849 commit 2ff13e4
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/pip/_internal/utils/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:/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:/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):
Expand Down

0 comments on commit 2ff13e4

Please sign in to comment.