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 brett.cannon
Recipients brett.cannon, exarkun
Date 2008-09-04.22:22:31
SpamBayes Score 4.96777e-08
Marked as misclassified No
Message-id <>
In-reply-to <>
On Thu, Sep 4, 2008 at 3:10 PM, Jean-Paul Calderone
<> wrote:
> New submission from Jean-Paul Calderone <>:
> 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.
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