Arfrever Frehtes Taifersar Arahesis added the comment: > Since I am not wrapping the warning, the default stacklevel seems to work on > all versions.
The purpose of stacklevel=2 here would be to make warning message indicate which file contains import of deprecated module. See below example, which shows that stacklevel=2 in formatter.py and imp.py results in message pointing to bbb.py as containing imports of deprecated modules: $ cat aaa.py import bbb $ cat bbb.py import formatter import imp import idlelib.idlever $ python3.5 -Wd -c 'import aaa' /tmp/bbb.py:1: DeprecationWarning: the formatter module is deprecated and will be removed in Python 3.6 import formatter /tmp/bbb.py:2: PendingDeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses import imp /usr/lib64/python3.5/idlelib/idlever.py:10: DeprecationWarning: The separate Idle version was eliminated years ago; idlelib.idlever is no longer used by Idle and will be removed in 3.6 or later. Use from sys import version IDLE_VERSION = version[:version.index(' ')] w.warn(__doc__, DeprecationWarning) $ ---------- nosy: +Arfrever _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue24199> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com