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 njs
Recipients Arfrever, barry, berker.peksag, brett.cannon, eric.snow, jwilk, larry, ncoghlan, njs, serhiy.storchaka, takluyver
Date 2015-08-14.19:40:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1439581241.79.0.870887043769.issue24305@psf.upfronthosting.co.za>
In-reply-to
Content
For 3.4/3.5 purposes, I propose a simpler algorithm: first, define a function which takes a module name and returns true if it is part of the internal warning machinery and false otherwise. This is easy because we know what import machinery we ship.

Then, to walk the stack in warnings.py, do something like:

frame = sys._get frame(1)
if is_import_machinery(frame.module_name):
  skip_frame = lambda modname: False
else:
  skip_frame = is_import_machinery
def next_unskipped_frame(f):
  new = f
  while new is f or skip_frame(new.module_name):
    new = new.caller
for i in range(stacklevel - 1):
  frame = next_unskipped_frame(frame)

This produces reasonable behavior for warnings issued by both regular user code and by warnings issued from inside the warning machinery, and it avoids having to explicitly keep track of call depths.

Then we can worry about coming up with an all-singing all-dancing generalized version for 3.6.
History
Date User Action Args
2015-08-14 19:40:41njssetrecipients: + njs, barry, brett.cannon, ncoghlan, larry, jwilk, Arfrever, eric.snow, takluyver, berker.peksag, serhiy.storchaka
2015-08-14 19:40:41njssetmessageid: <1439581241.79.0.870887043769.issue24305@psf.upfronthosting.co.za>
2015-08-14 19:40:41njslinkissue24305 messages
2015-08-14 19:40:41njscreate