diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-12-06 09:53:52 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-12-06 09:53:52 (GMT) |
commit | 8ef46be26ad1a3a5c4b542cf95832a4aca12c4ff (patch) | |
tree | 49c75f890c5846dfe4f88ff3f9478b18eaa36763 /Lib/warnings.py | |
parent | 3d3e9ffa8e7af0457621309b4fce076411d38ce6 (diff) | |
download | cpython-8ef46be26ad1a3a5c4b542cf95832a4aca12c4ff.zip cpython-8ef46be26ad1a3a5c4b542cf95832a4aca12c4ff.tar.gz cpython-8ef46be26ad1a3a5c4b542cf95832a4aca12c4ff.tar.bz2 |
catch_warnings() calls showwarning() if overriden
Issue #28089: Fix a regression introduced in warnings.catch_warnings(): call
warnings.showwarning() if it was overriden inside the context manager.
Diffstat (limited to 'Lib/warnings.py')
-rw-r--r-- | Lib/warnings.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Lib/warnings.py b/Lib/warnings.py index 2b407ff..0d16766 100644 --- a/Lib/warnings.py +++ b/Lib/warnings.py @@ -447,11 +447,20 @@ class catch_warnings(object): self._module._filters_mutated() self._showwarning = self._module.showwarning self._showwarnmsg = self._module._showwarnmsg + self._showwarnmsg_impl = self._module._showwarnmsg_impl if self._record: log = [] - def showarnmsg(msg): + + def showarnmsg_logger(msg): + nonlocal log log.append(msg) - self._module._showwarnmsg = showarnmsg + + self._module._showwarnmsg_impl = showarnmsg_logger + + # Reset showwarning() to the default implementation to make sure + # that _showwarnmsg() calls _showwarnmsg_impl() + self._module.showwarning = self._module._showwarning + return log else: return None @@ -463,6 +472,7 @@ class catch_warnings(object): self._module._filters_mutated() self._module.showwarning = self._showwarning self._module._showwarnmsg = self._showwarnmsg + self._module._showwarnmsg_impl = self._showwarnmsg_impl # filters contains a sequence of filter 5-tuples |