This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Thomas.Robitaille
Recipients Thomas.Robitaille
Date 2016-11-30.00:29:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1480465767.99.0.401403947818.issue28835@psf.upfronthosting.co.za>
In-reply-to
Content
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?
History
Date User Action Args
2016-11-30 00:29:28Thomas.Robitaillesetrecipients: + Thomas.Robitaille
2016-11-30 00:29:27Thomas.Robitaillesetmessageid: <1480465767.99.0.401403947818.issue28835@psf.upfronthosting.co.za>
2016-11-30 00:29:27Thomas.Robitaillelinkissue28835 messages
2016-11-30 00:29:27Thomas.Robitaillecreate