[New-bugs-announce] [issue11775] `bool(Counter({'a': 0'})) is True`

Ram Rachum report at bugs.python.org
Tue Apr 5 20:57:11 CEST 2011

New submission from Ram Rachum <cool-rr at cool-rr.com>:

bool(Counter({'a': 0'})) is True.

Is this wise? I want to be able to do:

    if my_counter:

To check whether my counter has any elements. Currently this seems to be impossible because of this bug.

Will we have to keep this weird behavior because of backwards compatibility? If so, perhaps `.elements` could be turned into a smart object so we could at least do `if my_counter.elements():` and get the expected result.

If you want a patch let me know and I'll write one.

components: Library (Lib)
messages: 133076
nosy: cool-RR
priority: normal
severity: normal
status: open
title: `bool(Counter({'a': 0'})) is True`
versions: Python 3.3, Python 3.4

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list