[Python-Dev] Warnings behave differently in Python 2 and Python 3?
(I assume that this list is appropriate for this topic, but if it
isn't, I will be grateful for being redirected to the appropriate
place.)
It seems that warnings behave differently in Python 2 and Python
3. Consider the following script.
def func():
warnings.warn("Blabla", RuntimeWarning)
warnings.simplefilter("ignore")
func()
warnings.simplefilter("always")
func()
When run with CPython 2.7, there is no output, when run with
CPython 3.5, there is the following output:
/tmp/test.py:4: RuntimeWarning: Blabla
warnings.warn("Blabla", RuntimeWarning)
Was there indeed a change of how warnings behave in Python 3? I
searched, but couldn't find any documentation for this.
Understanding how warnings work is especially important when
testing for them.
This is how I stumbled across this, in case anyone is interested:
https://gitlab.kwant-project.org/kwant/kwant/issues/1#note_2608
I also note that the current documentation still uses
DeprecationWarning in the example of how to suppress a warning:
https://docs.python.org/dev/library/warnings.html#temporarily-suppressing-warnings.
Since DeprecationWarning is disabled by default in modern Python,
perhaps a different warning would provide a better example?
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Warnings behave differently in Python 2 and Python 3?
You are looking for the bug fix http://bugs.python.org/issue4180:
"warnings.simplefilter("always") does not make warnings always show up"
Python 2.7 has a bug, Python 3.4.3+ behaves correctly.
It is surprising that Python 3.4.0 and Python 3.4.3 behaves
differently :-) (Ubuntu 14.04 uses Python 3.4.0..
Victor
2016-11-14 14:58 GMT+01:00 Christoph Groth :
> (I assume that this list is appropriate for this topic, but if it isn't, I
> will be grateful for being redirected to the appropriate place.)
>
> It seems that warnings behave differently in Python 2 and Python 3.
> Consider the following script.
>
>
> def func():
>warnings.warn("Blabla", RuntimeWarning)
>
> warnings.simplefilter("ignore")
> func()
> warnings.simplefilter("always")
> func()
>
>
> When run with CPython 2.7, there is no output, when run with CPython 3.5,
> there is the following output:
>
>
> /tmp/test.py:4: RuntimeWarning: Blabla
> warnings.warn("Blabla", RuntimeWarning)
>
>
> Was there indeed a change of how warnings behave in Python 3? I searched,
> but couldn't find any documentation for this.
>
> Understanding how warnings work is especially important when testing for
> them.
> This is how I stumbled across this, in case anyone is interested:
> https://gitlab.kwant-project.org/kwant/kwant/issues/1#note_2608
>
> I also note that the current documentation still uses DeprecationWarning in
> the example of how to suppress a warning:
> https://docs.python.org/dev/library/warnings.html#temporarily-suppressing-warnings.
> Since DeprecationWarning is disabled by default in modern Python, perhaps a
> different warning would provide a better example?
> ___
> Python-Dev mailing list
> [email protected]
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/victor.stinner%40gmail.com
___
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Warnings behave differently in Python 2 and Python 3?
Thanks, Victor, for the link to the bug fix! I suspected that the original mechanism was something like that, but I believed that it was so by design. I find it a bit surprising that CPython gets changed between versions in backwards-incompatible ways (even if it’s a bug fix) without a notice in "what's new"... Christoph ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Warnings behave differently in Python 2 and Python 3?
On 11/14/2016 4:44 PM, Christoph Groth wrote: Thanks, Victor, for the link to the bug fix! I suspected that the original mechanism was something like that, but I believed that it was so by design. I find it a bit surprising that CPython gets changed between versions in backwards-incompatible ways (even if it’s a bug fix) without a notice in "what's new"... It doesn't. What's New proper only lists new features, which only appear in x.y.0. But is includes a link to an updated 'changelog', which includes bug fixes, listed in separate sections for each release, including release candidates. "See the changelog for a full list of changes.": 2nd line of What's New in Python 3.5. -- Terry Jan Reedy ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
