Skip to content

Commit

Permalink
Always raise warnings for deprecated feature checks
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Oct 11, 2024
1 parent 3d9c05c commit afbf450
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Tests/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ def test(name: str, function: Callable[[str], str | None]) -> None:

def test_webp_transparency() -> None:
with pytest.warns(DeprecationWarning):
assert features.check("transp_webp") == features.check_module("webp")
assert (features.check("transp_webp") or False) == features.check_module("webp")


def test_webp_mux() -> None:
with pytest.warns(DeprecationWarning):
assert features.check("webp_mux") == features.check_module("webp")
assert (features.check("webp_mux") or False) == features.check_module("webp")


def test_webp_anim() -> None:
with pytest.warns(DeprecationWarning):
assert features.check("webp_anim") == features.check_module("webp")
assert (features.check("webp_anim") or False) == features.check_module("webp")


@skip_unless_feature("libjpeg_turbo")
Expand Down
3 changes: 2 additions & 1 deletion src/PIL/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ def check_feature(feature: str) -> bool | None:

module, flag, ver = features[feature]

if isinstance(flag, bool):
deprecate(f'check_feature("{feature}")', 12)
try:
imported_module = __import__(module, fromlist=["PIL"])
if isinstance(flag, bool):
deprecate(f'check_feature("{feature}")', 12)
return flag
return getattr(imported_module, flag)
except ModuleNotFoundError:
Expand Down

0 comments on commit afbf450

Please sign in to comment.