class_docstr: Context manager that resets warning registry for catching warnings
  
  Warnings can be slippery, because, whenever a warning is triggered, Python
  adds a ``__warningregistry__`` member to the *calling* module.  This makes
  it impossible to retrigger the warning in this module, whatever you put in
  the warnings filters.  This context manager accepts a sequence of `modules`
  as a keyword argument to its constructor and:
  
  * stores and removes any ``__warningregistry__`` entries in given `modules`
    on entry;
  * resets ``__warningregistry__`` to its previous state on exit.
  
  This makes it possible to trigger any warning afresh inside the context
  manager without disturbing the state of warnings outside.
  
  For compatibility with Python 3.0, please consider all arguments to be
  keyword-only.
  
  Parameters
  ----------
  record : bool, optional
      Specifies whether warnings should be captured by a custom
      implementation of ``warnings.showwarning()`` and be appended to a list
      returned by the context manager. Otherwise None is returned by the
      context manager. The objects appended to the list are arguments whose
      attributes mirror the arguments to ``showwarning()``.
  
      NOTE: nibabel difference from numpy: default is True
  
  modules : sequence, optional
      Sequence of modules for which to reset warnings registry on entry and
      restore on exit
  
  Examples
  --------
  >>> import warnings
  >>> with clear_and_catch_warnings(modules=[np.core.fromnumeric]):
  ...     warnings.simplefilter('always')
  ...     # do something that raises a warning in np.core.fromnumeric
class_docstr_tok: ["Context","manager","that","resets","warning","registry","for","catching","warnings","Warnings","can","be","slippery",",","because",",","whenever","a","warning","is","triggered",",","Python","adds","a","``","__warningregistry__","``","member","to","the","*","calling","*","module",".","This","makes","it","impossible","to","retrigger","the","warning","in","this","module",",","whatever","you","put","in","the","warnings","filters",".","This","context","manager","accepts","a","sequence","of","`","modules","`","as","a","keyword","argument","to","its","constructor","and",":","*","stores","and","removes","any","``","__warningregistry__","``","entries","in","given","`","modules","`","on","entry",";","*","resets","``","__warningregistry__","``","to","its","previous","state","on","exit",".","This","makes","it","possible","to","trigger","any","warning","afresh","inside","the","context","manager","without","disturbing","the","state","of","warnings","outside",".","For","compatibility","with","Python","3.0",",","please","consider","all","arguments","to","be","keyword-only",".","Parameters","--","--","--","--","--","record",":","bool",",","optional","Specifies","whether","warnings","should","be","captured","by","a","custom","implementation","of","``","warnings.showwarning","(",")","``","and","be","appended","to","a","list","returned","by","the","context","manager",".","Otherwise","None","is","returned","by","the","context","manager",".","The","objects","appended","to","the","list","are","arguments","whose","attributes","mirror","the","arguments","to","``","showwarning","(",")","``",".","NOTE",":","nibabel","difference","from","numpy",":","default","is","True","modules",":","sequence",",","optional","Sequence","of","modules","for","which","to","reset","warnings","registry","on","entry","and","restore","on","exit","Examples","--","--","--","--",">",">",">","import","warnings",">",">",">","with","clear_and_catch_warnings","(","modules=","[","np.core.fromnumeric","]",")",":","...","warnings.simplefilter","(","'always","'",")","...","#","do","something","that","raises","a","warning","in","np.core.fromnumeric"]
code: def __enter__(self):
      for mod in self.modules:
          if hasattr(mod, "__warningregistry__"):
              mod_reg = mod.__warningregistry__
              self._warnreg_copies[mod] = mod_reg.copy()
              mod_reg.clear()
      return super().__enter__()
  
imports: from __future__ import annotations
  import os
  import re
  import sys
  import typing
  import unittest
  import warnings
  from contextlib import nullcontext
  from itertools import zip_longest
  import numpy
  import pytest
  from numpy.testing import assert_array_equal
  from .helpers import assert_data_similar, bytesio_filemap, bytesio_round_trip
  from .np_features import memmap_after_ufunc
label_desc: Use image node_id 2 for calling the clear_and_catch_warnings obj's underlying member method code with example usage: obj.__enter__() and returns: super