[issue3781] warnings.catch_warnings fails gracelessly when recording warnings but no warnings are emitted

Brett Cannon report at bugs.python.org
Tue Sep 9 01:17:34 CEST 2008


Brett Cannon <brett at python.org> added the comment:

On Mon, Sep 8, 2008 at 3:12 PM, Benjamin Peterson
<report at bugs.python.org> wrote:
>
> Benjamin Peterson <musiccomposition at gmail.com> added the comment:
>
> The patch mostly looks good. However, all the w[-1] logic looks rather
> verbose to me since its main use case in testing will be making sure
> *one* warning happened. Returning a list adds the extra step of checking
> the length and then indexing it for the warning validation. I'm not
> completely suggesting that you bring back the smart list, but maybe an
> option on catch_warning to just yield the WarningMessage on __enter__.
>

Well, the real question is whether most users will use this for
testing, or for temporarily suppressing warnings. The stdlib is not a
normal use-case in this regard since we have to be so careful with
giving deprecations.

I honest don't fine the [-1] indexing that bad and I had to add all of
them. =) Makes it explicit you are assuming there is at least one
warnings (and probably only one) and you should check that there was
not an extra one.

I will wait to see if Barry has anything to say on the matter since he
pushed for the change.

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3781>
_______________________________________


More information about the Python-bugs-list mailing list