On 21.09.15 20:32, Brett Cannon wrote:
On Mon, 21 Sep 2015 at 10:15 Serhiy Storchaka <storch...@gmail.com <mailto:storch...@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.warn_deprecated(message)" function that's implemented as: > > def warn_deprecated(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.deprecate_module() 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.
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com