Description:
While working on merging remove_arg and deprecated_kwarg in #7256, I noticed that the code for detecting the proper stacklevel of shown deprecation warnings is broken when the functions are applied on an already decorated function (see reproducing example below). In both cases the outer decorator shows the warning source as originating from scikit-image/skimage/_shared/utils.py.
I don't exactly follow the code dealing with this. But I am working on fixing it in #7256.
Way to reproduce:
# File: scikit-image/local/debug.py
from skimage._shared.utils import remove_arg, deprecate_kwarg
@remove_arg("b", changed_version="1")
@remove_arg("c", changed_version="1")
def foo(a, b, c, d):
pass
@deprecate_kwarg({"a": "b"}, deprecated_version="1")
@deprecate_kwarg({"c": "d"}, deprecated_version="1")
def bar(*, b, d):
pass
foo(1, 2, 3, 4)
bar(a=1, b=2, c=3, d=4)
shows the following warnings:
scikit-image/skimage/_shared/utils.py:150: FutureWarning: b argument is deprecated and will be removed in version 1. To avoid this warning, please do not use the b argument. Please see foo documentation for more details.
warnings.warn(warning_msg, FutureWarning, stacklevel=stacklevel)
scikit-image/local/debug.py:18: FutureWarning: c argument is deprecated and will be removed in version 1. To avoid this warning, please do not use the c argument. Please see foo documentation for more details.
foo(1, 2, 3, 4)
scikit-image/skimage/_shared/utils.py:268: FutureWarning: `a` is a deprecated argument name for `bar`. Please use `b` instead.
warnings.warn(
scikit-image/local/debug.py:20: FutureWarning: `c` is a deprecated argument name for `bar`. Please use `d` instead.
bar(a=1, b=2, c=3, d=4)
Version information:
3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801]
Linux-6.6.3-arch1-1-x86_64-with-glibc2.38
scikit-image version: 0.23.0rc0.dev0+git20231130.604d0776f
numpy version: 1.26.2
Description:
While working on merging
remove_arganddeprecated_kwargin #7256, I noticed that the code for detecting the proper stacklevel of shown deprecation warnings is broken when the functions are applied on an already decorated function (see reproducing example below). In both cases the outer decorator shows the warning source as originating fromscikit-image/skimage/_shared/utils.py.I don't exactly follow the code dealing with this. But I am working on fixing it in #7256.
Way to reproduce:
shows the following warnings:
Version information: