New submission from Thomas Robitaille: In Python 3.5, the following code:
import warnings def deal_with_warning(*args, **kwargs): print("warning emitted") with warnings.catch_warnings(record=True): warnings.showwarning = deal_with_warning warnings.warn("This is a warning") results in "warning emitted" being printed to the terminal. In Python 3.6 however (at least in 3.6b1), nothing is printed, meaning that ``deal_with_warning`` is not getting called. I bisected the CPython history and tracked it down to the changes in this issue: https://bugs.python.org/issue26568 However it doesn't look like this was an intentional change in behavior, since it says in the description of that issue: "For backward compatibility, warnings.showmsg() calls warnings.showwarning() if warnings.showwarning() was replaced. Same for warnings.formatmsg(): call warnings.formatwarning() if replaced." So I believe this is a bug? (since backward-compatibility is not preserved). If not, should the change in behavior be mentioned in the changelog? ---------- messages: 282056 nosy: Thomas.Robitaille priority: normal severity: normal status: open title: Change in behavior when overriding warnings.showwarning and with catch_warnings(record=True) versions: Python 3.6 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue28835> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com