[Python-Dev] Make stacklevel=2 by default in warnings.warn() (original) (raw)
Serhiy Storchaka storchaka at gmail.com
Mon Sep 21 20:28:51 CEST 2015
- Previous message (by thread): [Python-Dev] Make stacklevel=2 by default in warnings.warn()
- Next message (by thread): [Python-Dev] Make stacklevel=2 by default in warnings.warn()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 21.09.15 20:32, Brett Cannon wrote:
On Mon, 21 Sep 2015 at 10:15 Serhiy Storchaka <storchaka at gmail.com_ _<mailto:storchaka at gmail.com>> wrote: On 21.09.15 12:05, Nick Coghlan wrote: > Passing "stacklevel=2" for API deprecations is by no means obvious > though, so perhaps it makes sense to add a > "warnings.warndeprecated(message)" function that's implemented as: > > def warndeprecated(message, stacklevel=1): > return warnings.warn(message, DeprecationWarning, > stacklevel=(2+stacklevel)). This will not fix tons of modules that are not aware of correct stacklevel. The long-term solution to this is to add a warnings.deprecatemodule() function which does the right thing and simply not expose the stacklevel argument to users. We can then consider warnings.warn() more of a power user function and make the stacklevel a keyword-only argument with no default value (although I can already hear Raymond saying "but the Python 2 users" for that part of the idea =).
warnings.deprecate_module() will do the right thing only for deprecated modules, but most deprecations refer to separate functions.
- Previous message (by thread): [Python-Dev] Make stacklevel=2 by default in warnings.warn()
- Next message (by thread): [Python-Dev] Make stacklevel=2 by default in warnings.warn()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]