Brett Cannon <[EMAIL PROTECTED]> added the comment: On Thu, Sep 4, 2008 at 3:10 PM, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > > New submission from Jean-Paul Calderone <[EMAIL PROTECTED]>: > > This example shows the behavior: > > from warnings import catch_warnings > > def test(): > with catch_warnings(True) as w: > assert str(w.message) == "foo", "%r != %r" % (w.message, "foo") > > test() > > This fails with an IndexError from the `w.message`. That's a bit > surprising, and since this is mostly an API useful for testing, it'd be > much better if it had a well-defined, documented (ie, stable and likely > to continue working in the next release of Python) error mode. >
The question is what exception to raise when no warning has been recorded. AttributeError goes with the idea that the attributes are just not set since no warnings are there to set the attributes. LookupError doesn't seem quite right. TypeError is definitely wrong since it has nothing to do with the type of anything. So unless someone comes up with a better suggestion I will change __getattr__ on catch_warnings to raise AttributeError when IndexError is raised because no warning is currently recorded. _______________________________________ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3781> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com