Skip to content

Commit 10c0f0d

Browse files
committed
Hide feature flag if deprecated behaviour is gone
1 parent 7bbbaa3 commit 10c0f0d

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

src/pip/_internal/utils/deprecation.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ def deprecated(
9797
),
9898
(
9999
feature_flag,
100-
"You can use the flag --use-feature={} to test the upcoming behaviour.",
100+
"You can use the flag --use-feature={} to test the upcoming behaviour."
101+
if not is_gone
102+
else None,
101103
),
102104
(
103105
issue,
@@ -108,7 +110,7 @@ def deprecated(
108110
message = " ".join(
109111
format_str.format(value)
110112
for value, format_str in message_parts
111-
if value is not None
113+
if format_str is not None and value is not None
112114
)
113115

114116
# Raise as an error if this behaviour is deprecated.

tests/unit/test_utils.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -920,20 +920,22 @@ def test_deprecated_raises_error_if_too_old(replacement, issue, feature_flag):
920920

921921
assert "DEPRECATION: Stop doing this!" in message
922922
assert "1.0" in message
923+
assert str(feature_flag) not in message
923924
# Ensure non-None values are mentioned.
924-
for item in [replacement, issue, feature_flag]:
925+
for item in [replacement, issue]:
925926
if item is not None:
926927
assert str(item) in message
927928

928929

929930
@pytest.mark.usefixtures("patch_deprecation_check_version")
930-
def test_deprecated_message_reads_well():
931+
def test_deprecated_message_reads_well_past():
931932
with pytest.raises(PipDeprecationWarning) as exception:
932933
deprecated(
933934
reason="Stop doing this!",
934935
gone_in="1.0", # this matches the patched version.
935936
replacement="to be nicer",
936-
issue="100000", # I hope we never reach this number.
937+
feature_flag="magic-8-ball",
938+
issue="100000",
937939
)
938940

939941
message = exception.value.args[0]
@@ -946,6 +948,29 @@ def test_deprecated_message_reads_well():
946948
)
947949

948950

951+
@pytest.mark.usefixtures("patch_deprecation_check_version")
952+
def test_deprecated_message_reads_well_future():
953+
with pytest.warns(PipDeprecationWarning) as record:
954+
deprecated(
955+
reason="Stop doing this!",
956+
gone_in="2.0", # this is greater than the patched version.
957+
replacement="to be nicer",
958+
feature_flag="crisis",
959+
issue="100000",
960+
)
961+
962+
assert len(record) == 1
963+
message = record[0].message.args[0]
964+
965+
assert message == (
966+
"DEPRECATION: Stop doing this! "
967+
"pip 2.0 will enforce this behaviour change. "
968+
"A possible replacement is to be nicer. "
969+
"You can use the flag --use-feature=crisis to test the upcoming behaviour. "
970+
"Discussion can be found at https://github.com/pypa/pip/issues/100000"
971+
)
972+
973+
949974
def test_make_setuptools_shim_args():
950975
# Test all arguments at once, including the overall ordering.
951976
args = make_setuptools_shim_args(

0 commit comments

Comments
 (0)