Message282056
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? |
|
Date |
User |
Action |
Args |
2016-11-30 00:29:28 | Thomas.Robitaille | set | recipients:
+ Thomas.Robitaille |
2016-11-30 00:29:27 | Thomas.Robitaille | set | messageid: <1480465767.99.0.401403947818.issue28835@psf.upfronthosting.co.za> |
2016-11-30 00:29:27 | Thomas.Robitaille | link | issue28835 messages |
2016-11-30 00:29:27 | Thomas.Robitaille | create | |
|