[New-bugs-announce] [issue22801] collections.Counter, when empty, doesn't raise an error with &= when other is an incompatible type

Ethan Furman report at bugs.python.org
Wed Nov 5 18:44:31 CET 2014


New submission from Ethan Furman:

test script:
---------------------------------------
from collections import Counter
empty_counter = Counter()
counter = Counter('abbc')
empty_counter &= 5
counter &= 5
---------------------------------------

results:
---------------------------------------
Traceback (most recent call last):
  File "blah.py", line 5, in <module>
    counter &= 5
  File "/home/ethan/source/python/issue22778/Lib/collections/__init__.py", line 780, in __iand__
    other_count = other[elem]
TypeError: 'int' object is not subscriptable
----------------------------------------

As can be seen, the error does not show up when the Counter is empty, which could lead to hard to diagnose bugs.

----------
assignee: rhettinger
files: issue22778.stoneleaf.01.patch
keywords: patch
messages: 230699
nosy: ethan.furman, rhettinger
priority: normal
severity: normal
stage: patch review
status: open
title: collections.Counter, when empty, doesn't raise an error with &= when other is an incompatible type
type: behavior
versions: Python 3.4, Python 3.5
Added file: http://bugs.python.org/file37136/issue22778.stoneleaf.01.patch

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


More information about the New-bugs-announce mailing list