A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2015-September/141743.html below:

[Python-Dev] Make stacklevel=2 by default in warnings.warn()

[Python-Dev] Make stacklevel=2 by default in warnings.warn() [Python-Dev] Make stacklevel=2 by default in warnings.warn()Victor Stinner victor.stinner at gmail.com
Mon Sep 21 09:18:28 CEST 2015
2015-09-20 8:44 GMT+02:00 Serhiy Storchaka <storchaka at gmail.com>:
> I propose to make the default value of stacklevel to be 2.
> I think that unlikely this will break existing code.

Consider this simple script:
---
import warnings
warnings.warn("here")
---

Currrent output:
---
x.py:3: UserWarning: here
  warnings.warn("here")
---

=> it shows the script name (x.py), the line number and the line, as expected.

Now try stacklevel=2:
---
import warnings
warnings.warn("here", stacklevel=2)
---

New output:
---
sys:1: UserWarning: here
---

"sys:1" is not really useful :-/

I would describe this as a regression, not an enhancement.

It's hard to find a "good" default value. It's better to always
specify stacklevel :-)

Victor
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4