[Python] Python - showing 'once' warnings again (resetting all warning registries)

Discussão em 'Python' iniciado por Stack, Novembro 26, 2025.

  1. Stack

    Stack Membro Participativo

    is there a way to reset the __warningregistry__ of all loaded functions at once?

    I would like to force all warnings that are filtered with the 'once' filter to show again. I have found no way of doing this aside from calling <func>.__globals__['__warningregistry__'].clear() on every function that I have loaded (including those that are part of an imported module.)

    So, what I want is something like a warnings.clear() function to do the following:

    >>> import warnings
    >>> warnings.warn('blah')
    WARNING:root:blah ->UserWarning at ...
    >>> warnings.warn('blah')
    >>> warnings.clear()
    >>> warnings.warn('blah')
    WARNING:root:blah ->UserWarning at ...


    And I want this warnings.clear() function to also clear all warning registries, not just the current name-space.

    Is this already existent? Perhaps I'm missing something obvious, or using the module incorrectly?

    Continue reading...

Compartilhe esta Página