Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Tests/test_deprecate.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ def test_unknown_version():
_deprecate.deprecate("Old thing", 12345, "new thing")


@pytest.mark.parametrize(
"deprecated, plural, expected",
[
(
"Old thing",
False,
r"Old thing is deprecated and should be removed\.",
),
(
"Old things",
True,
r"Old things are deprecated and should be removed\.",
),
],
)
def test_old_version(deprecated, plural, expected):
expected = r""
with pytest.raises(RuntimeError, match=expected):
_deprecate.deprecate(deprecated, 1, plural=plural)


def test_plural():
expected = (
r"Old things are deprecated and will be removed in Pillow 10 \(2023-07-01\)\. "
Expand Down
10 changes: 7 additions & 3 deletions src/PIL/_deprecate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import warnings

from . import __version__


def deprecate(
deprecated: str,
Expand Down Expand Up @@ -38,10 +40,12 @@ def deprecate(

is_ = "are" if plural else "is"

if when == 10:
removed = "Pillow 10 (2023-07-01)"
elif when is None:
if when is None:
removed = "a future version"
elif when <= int(__version__.split(".")[0]):
raise RuntimeError(f"{deprecated} {is_} deprecated and should be removed.")
elif when == 10:
removed = "Pillow 10 (2023-07-01)"
else:
raise ValueError(f"Unknown removal version, update {__name__}?")

Expand Down