MCPcopy Index your code
hub / github.com/numpy/numpy / suppress_warnings

Class suppress_warnings

numpy/testing/_private/utils.py:2291–2577  ·  view source on GitHub ↗

Context manager and decorator doing much the same as ``warnings.catch_warnings``. However, it also provides a filter mechanism to work around https://bugs.python.org/issue4180. This bug causes Python before 3.4 to not reliably show warnings again after they have been ignor

Source from the content-addressed store, hash-verified

2289
2290
2291class suppress_warnings:
2292 """
2293 Context manager and decorator doing much the same as
2294 ``warnings.catch_warnings``.
2295
2296 However, it also provides a filter mechanism to work around
2297 https://bugs.python.org/issue4180.
2298
2299 This bug causes Python before 3.4 to not reliably show warnings again
2300 after they have been ignored once (even within catch_warnings). It
2301 means that no "ignore" filter can be used easily, since following
2302 tests might need to see the warning. Additionally it allows easier
2303 specificity for testing warnings and can be nested.
2304
2305 .. deprecated:: 2.4
2306
2307 This is deprecated. Use `warnings.filterwarnings` or
2308 ``pytest.filterwarnings`` instead.
2309
2310 Parameters
2311 ----------
2312 forwarding_rule : str, optional
2313 One of "always", "once", "module", or "location". Analogous to
2314 the usual warnings module filter mode, it is useful to reduce
2315 noise mostly on the outmost level. Unsuppressed and unrecorded
2316 warnings will be forwarded based on this rule. Defaults to "always".
2317 "location" is equivalent to the warnings "default", match by exact
2318 location the warning warning originated from.
2319
2320 Notes
2321 -----
2322 Filters added inside the context manager will be discarded again
2323 when leaving it. Upon entering all filters defined outside a
2324 context will be applied automatically.
2325
2326 When a recording filter is added, matching warnings are stored in the
2327 ``log`` attribute as well as in the list returned by ``record``.
2328
2329 If filters are added and the ``module`` keyword is given, the
2330 warning registry of this module will additionally be cleared when
2331 applying it, entering the context, or exiting it. This could cause
2332 warnings to appear a second time after leaving the context if they
2333 were configured to be printed once (default) and were already
2334 printed before the context was entered.
2335
2336 Nesting this context manager will work as expected when the
2337 forwarding rule is "always" (default). Unfiltered and unrecorded
2338 warnings will be passed out and be matched by the outer level.
2339 On the outmost level they will be printed (or caught by another
2340 warnings context). The forwarding rule argument can modify this
2341 behaviour.
2342
2343 Like ``catch_warnings`` this context manager is not threadsafe.
2344
2345 Examples
2346 --------
2347
2348 With a context manager::

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…