Patches item #850482, was opened at 2003-11-28 00:12 Message generated for change (Comment added) made by zseil You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=850482&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Library (Lib) Group: Python 2.4 Status: Open Resolution: None Priority: 5 Private: No Submitted By: Walter Dörwald (doerwalter) Assigned to: Nobody/Anonymous (nobody) Summary: Enhance frame handing in warnings.warn() Initial Comment: This patch enhances warnings.warn() in the following way: The stacklevel passed in may be negative. In that case the call stack is searched for the innermost frame whose module name differs in the first -stacklevel components. This frame will be used in the report. So when you have the following call stack: m1.f() m1.m11.f() m1.m12.f() m2.m21.f() m2.m22.f() and the innermost function() m2.m22.f() call warnings.warn() with a stacklevel of -2 the frame reported will be from m1.m12.f(), because it is the first one from outside the m2 package. ---------------------------------------------------------------------- >Comment By: Žiga Seilnacht (zseil) Date: 2007-04-02 10:41 Message: Logged In: YES user_id=1326842 Originator: NO I don't know how desireable this feature is, but I think that a better solution would be to add a new parameter to warnings.warn(), instead of reusing the old one. Also, your description is wrong; when warn() in your example is called with stacklevel -2, the reported frame is m2.m21.f(). To get your result, you have to call warn() with stacklevel -1. I think that a better solution would be to add a skipmodules='moduleprefix' parameter to the warn() function. warn() would then simply look for the first frame whose module name doesn't start with this prefix. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=850482&group_id=5470 _______________________________________________ Patches mailing list [email protected] http://mail.python.org/mailman/listinfo/patches
