This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author exarkun
Recipients exarkun
Date 2008-10-22.21:55:24
SpamBayes Score 8.7270604e-07
Marked as misclassified No
Message-id <1224712526.35.0.138565894307.issue4182@psf.upfronthosting.co.za>
In-reply-to
Content
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:

  exarkun@charm:~$ 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

  exarkun@charm:~$ ~/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.
History
Date User Action Args
2008-10-22 21:55:26exarkunsetrecipients: + exarkun
2008-10-22 21:55:26exarkunsetmessageid: <1224712526.35.0.138565894307.issue4182@psf.upfronthosting.co.za>
2008-10-22 21:55:25exarkunlinkissue4182 messages
2008-10-22 21:55:24exarkuncreate