Author brett.cannon
Recipients brett.cannon, exarkun
Date 2008-09-04.22:22:31
SpamBayes Score 4.96777e-08
Marked as misclassified No
Message-id <bbaeab100809041522h2bc74ddfl2c920be5b308ccb5@mail.gmail.com>
In-reply-to <1220566209.35.0.614126643007.issue3781@psf.upfronthosting.co.za>
Content
On Thu, Sep 4, 2008 at 3:10 PM, Jean-Paul Calderone
<report@bugs.python.org> wrote:
>
> New submission from Jean-Paul Calderone <exarkun@divmod.com>:
>
> 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.
History
Date User Action Args
2008-09-04 22:22:33brett.cannonsetrecipients: + brett.cannon, exarkun
2008-09-04 22:22:32brett.cannonlinkissue3781 messages
2008-09-04 22:22:31brett.cannoncreate