From e24953cf7420ceb5a261c1a733d924cdc506d1a7 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 30 Jan 2016 09:17:47 -0600 Subject: [PATCH] Cleanup the _warnings module --- skimage/_shared/_warnings.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/skimage/_shared/_warnings.py b/skimage/_shared/_warnings.py index f6b4bdbc..c93bbc33 100644 --- a/skimage/_shared/_warnings.py +++ b/skimage/_shared/_warnings.py @@ -1,11 +1,11 @@ -__all__ = ['all_warnings', 'expected_warnings'] - from contextlib import contextmanager import sys import warnings import inspect import re +__all__ = ['all_warnings', 'expected_warnings', 'warn'] + def warn(message, category=None, stacklevel=2): """A version of `warnings.warn` with a default stacklevel of 2. @@ -98,7 +98,8 @@ def expected_warnings(matching): that may produce different warnings. The behaviors can be combined. If you pass multiple patterns, you get an orderless "and", where all of the warnings must be raised. - If you use the "|" operator in a pattern, you can catch one of several warnings. + If you use the "|" operator in a pattern, you can catch one of several + warnings. Finally, you can use "|\A\Z" in a pattern to signify it as optional. """ @@ -106,7 +107,7 @@ def expected_warnings(matching): # enter context yield w # exited user context, check the recorded warnings - remaining = [m for m in matching if not '\A\Z' in m.split('|')] + remaining = [m for m in matching if '\A\Z' not in m.split('|')] for warn in w: found = False for match in matching: