New submission from Matthias Bussonnier: The warning module is extremely useful, especially the ability to change various level of verbosity and filter by multiple criteria.
It is though sometime hard to pinpoint why a warning was triggered, or actually what triggered a warning. This is often due to the fact that libraries don't set the `stacklevel=...` correctly, that it is hard to get right (like at import time), or because warnings get triggered by complex, not obvious codepaths. One workaround is to switch from `always`/`once` to "error" to raise exceptions, but that can be quite troublesome in production, if other warnings are encountered in the meantime. Would it be accepted to add a warning filter type "stack" (or whatever name please you ...) that would not only print the current warning, but the stack leading to it. That is to say output almost identical as "error" but not actually raising ? Assuming above is reasonable, I have a working patch (both in the c and py implementation of warnings), though it can't seem to find how respect the `stacklevel=...` parameter unless `warn_explicit` is changed to allow an additional `frame` argument. Would adding this field be acceptable ? Or arguably, if one is interested in the stack, ignoring the stacklevel may make sens as one may want to explore the full reason of the warning (ie its source that may be hidden by stacklevel=... ) , and not only what triggered it. ---------- components: Library (Lib) messages: 289066 nosy: mbussonn priority: normal severity: normal status: open title: Ability to filter warnings to print current stack type: enhancement versions: Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue29731> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com