John Mark Vandenberg added the comment: 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. ---------- nosy: +John.Mark.Vandenberg _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25493> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com