New submission from Jean-Paul Calderone <[EMAIL PROTECTED]>: In Python 2.5 and earlier, passing stacklevel=0 to warnings.warn resulted in a warning shown which pointed to warnings.py. In Python 2.6, passing a stacklevel of 0 results in the warning shown pointing to the file containing the call to warnings.warn. To illustrate:
[EMAIL PROTECTED]:~$ python Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import warnings >>> def f(): ... warnings.warn("foo", stacklevel=0) ... >>> f() /usr/lib/python2.5/warnings.py:41: UserWarning: foo lineno = caller.f_lineno >>> as compared to [EMAIL PROTECTED]:~$ ~/Projects/python/branches/release26-maint/python Python 2.6+ (trunk:66997, Oct 22 2008, 14:43:32) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import warnings >>> def f(): ... warnings.warn("foo", stacklevel=0) ... >>> f() __main__:2: UserWarning: foo >>> This breaks code which assumes that stacklevel=0 will result in a different file than stacklevel=1. ---------- messages: 75116 nosy: exarkun severity: normal status: open title: warnings.warn shows the wrong filename and line number for stacklevel of 0 versions: Python 2.6 _______________________________________ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue4182> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com