◐ Shell
clean mode source ↗

Message 230278 - Python tracker

Indeed -- we mostly discuss with each other to try and sway his opinion.  :)

stdlib types should not let every error bubble up.  Consider a dict:
----------------------------------------------------------------
--> d = {}
--> d += 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +=: 'dict' and 'int'
----------------------------------------------------------------

now look at Counter
----------------------------------------------------------------
--> from collections import Counter
--> c = Counter()
--> c += 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ethan/source/python/cpython/Lib/collections/__init__.py", line 709, in __iadd__
    for elem, count in other.items():
AttributeError: 'int' object has no attribute 'items'
----------------------------------------------------------------

Counter is not user-friendly in this case.

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.