Allow for custom stacklevel in deprecations

This commit is contained in:
Andrew Murray 2025-06-18 22:19:20 +10:00
parent d23d56e195
commit 79e0b0b6ad
2 changed files with 3 additions and 2 deletions

View File

@ -1370,7 +1370,7 @@ def _save(
msg = f"cannot write mode {mode} as PNG" msg = f"cannot write mode {mode} as PNG"
raise OSError(msg) from e raise OSError(msg) from e
if outmode == "I": if outmode == "I":
deprecate("Saving I mode images as PNG", 13) deprecate("Saving I mode images as PNG", 13, stacklevel=4)
# #
# write minimal PNG file # write minimal PNG file

View File

@ -12,6 +12,7 @@ def deprecate(
*, *,
action: str | None = None, action: str | None = None,
plural: bool = False, plural: bool = False,
stacklevel: int = 3,
) -> None: ) -> None:
""" """
Deprecations helper. Deprecations helper.
@ -67,5 +68,5 @@ def deprecate(
warnings.warn( warnings.warn(
f"{deprecated} {is_} deprecated and will be removed in {removed}{action}", f"{deprecated} {is_} deprecated and will be removed in {removed}{action}",
DeprecationWarning, DeprecationWarning,
stacklevel=3, stacklevel=stacklevel,
) )