diff --git a/skimage/__init__.py b/skimage/__init__.py index f5f97130..14b3e448 100644 --- a/skimage/__init__.py +++ b/skimage/__init__.py @@ -158,7 +158,9 @@ else: if sys.version.startswith('2.6'): - warnings.warn("Python 2.6 is deprecated and will not be supported in scikit-image 0.13+", stacklevel=2) + msg = ("Python 2.6 is deprecated and will not be supported in" + "scikit-image 0.13+") + warnings.warn(msg, stacklevel=2) del warnings, functools, osp, imp, sys diff --git a/skimage/_shared/_warnings.py b/skimage/_shared/_warnings.py index 522a0e89..d397d8e9 100644 --- a/skimage/_shared/_warnings.py +++ b/skimage/_shared/_warnings.py @@ -7,11 +7,13 @@ import re __all__ = ['all_warnings', 'expected_warnings', 'warn'] -def warn(message, **kwargs): +def warn(message, category=None, stacklevel=2): """A version of `warnings.warn` with a default stacklevel of 2. """ - kwargs.setdefault('stacklevel', 2) - warnings.warn(message, **kwargs) + if category is not None: + warnings.warn(message, category=category, stacklevel=stacklevel) + else: + warnings.warn(message, stacklevel=stacklevel) @contextmanager diff --git a/skimage/measure/_ccomp.pyx b/skimage/measure/_ccomp.pyx index 0da764fb..e7088d24 100644 --- a/skimage/measure/_ccomp.pyx +++ b/skimage/measure/_ccomp.pyx @@ -4,7 +4,7 @@ #cython: wraparound=False import numpy as np -import warnings +from .._shared.utils import warn cimport numpy as cnp @@ -47,9 +47,9 @@ ctypedef struct bginfo: cdef void get_bginfo(background_val, bginfo *ret) except *: if background_val is None: - warnings.warn(DeprecationWarning( + warn(DeprecationWarning( 'The default value for `background` will change to 0 in v0.12' - ), stacklevel=2) + )) ret.background_val = -1 else: ret.background_val = background_val diff --git a/skimage/viewer/utils/core.py b/skimage/viewer/utils/core.py index 8bffaafe..c44f0991 100644 --- a/skimage/viewer/utils/core.py +++ b/skimage/viewer/utils/core.py @@ -8,7 +8,7 @@ from matplotlib.colors import LinearSegmentedColormap if has_qt and 'agg' not in mpl.get_backend().lower(): warn("Recommended matplotlib backend is `Agg` for full " - "skimage.viewer functionality.") + "skimage.viewer functionality.") __all__ = ['init_qtapp', 'start_qtapp', 'RequiredAttr', 'figimage',