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 jayvdb
Recipients Arfrever, bevan, brett.cannon, jayvdb, lazka, r.david.murray, serhiy.storchaka
Date 2015-12-10.06:00:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1449727222.63.0.780901072163.issue25493@psf.upfronthosting.co.za>
In-reply-to
Content
It seems like there is already sufficient detection of invalid stack levels in warnings.warn, and one of the code paths does `module = "<string>"` and later another does `filename = module`, so `filename` can be intentionally junk data, which will be passed to `linecache`.

I expect this could be satisfactorily resolved by warn() setting filename = '<invalid stacklevel>', and `formatwarning` not invoking linecache when the filename is '<string>', '<invalid stacklevel>', etc., or at least ignoring the exception from linecache when the filename is <foo>.

Looking forward, why not let Python 3.6 warn() behave 'better' when the stacklevel is invalid.

e.g. it could raise ValueError (ouch, but 'correct'), or it could reset the stacklevel to 1 (a sensible fallback) and issue an auxillary SyntaxWarning to inform everyone that the stacklevel requested was incorrect.
History
Date User Action Args
2015-12-10 06:00:22jayvdbsetrecipients: + jayvdb, brett.cannon, Arfrever, r.david.murray, serhiy.storchaka, bevan, lazka
2015-12-10 06:00:22jayvdbsetmessageid: <1449727222.63.0.780901072163.issue25493@psf.upfronthosting.co.za>
2015-12-10 06:00:22jayvdblinkissue25493 messages
2015-12-10 06:00:22jayvdbcreate