

Issues opened for list ( issue22778) and deque ( issue22779). The behavior exhibited by set() is correct, and the behavior for array and bytearray are fine, as the error message is even more helpful. TypeError: can only extend array with array (not "int")

I also think returning NotImplemented would be the right thing here. There are other areas of Counter that accept arbitrary mappings, so I would be fine the _ixxx_ methods also accepting arbitrary mappings, but if the thing passed in *will not* work with Counter, then returning NotImplemented is the appropriate course of action. TypeError: unsupported operand type(s) for +=: 'dict' and 'int'įile "/home/ethan/source/python/cpython/Lib/ collections/_init_.py", line 709, in _iadd_Ĭounter is not user-friendly in this case. Stdlib types should not let every error bubble up. Indeed - we mostly discuss with each other to try and sway his opinion. Why should subtract explicitly support other data types, but not _sub_/_isub_? But Raymond's opinion should hold the most weight here. Personally I'd drop the isinstance checks and let the errors bubble up as they may. However, _add_ does an ininstance check, so it is hard to see why _iadd_ does not.

'counter' in the docstrings is in lower case, so that says nothing dispositive. If we want to relax that we could check for an 'items' attribute and 'return NotImplemented' if it isn't there, but one or the other should definitely happen. That would prevent it from working with "work alike" (duck type) classes, though.Īs I noted in my review, the docstring specifically says "other Counter". Instead, it should return 'NotImplemented' if 'other' is not a 'collections.Counter'Īuthor: R. FilesĬurrently, in-place operations on 'collections.Counter' with unsupported types raises an 'AttributeError'.įile "/usr/local/Cellar/python3/3.4.2_1/Frameworks/amework/Versions/3.4/lib/python3.4/ collections/_init_.py", line 709, in _iadd_ĪttributeError: 'int' object has no attribute 'items' Jim.Jewett, Joshua.Chin, ethan.furman, pitrou, r.david.murray, rhettinger, serhiy.storchakaĬreated on 15:06 by Joshua.Chin, last changed 14:58 by admin. Collections.Counter's in-place operators should return NotImplemented for unsupported types
