Message230278
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. |
|
Date |
User |
Action |
Args |
2014-10-30 18:00:49 | ethan.furman | set | recipients:
+ ethan.furman, rhettinger, r.david.murray, Joshua.Chin |
2014-10-30 18:00:49 | ethan.furman | set | messageid: <1414692049.49.0.718328518303.issue22766@psf.upfronthosting.co.za> |
2014-10-30 18:00:49 | ethan.furman | link | issue22766 messages |
2014-10-30 18:00:49 | ethan.furman | create | |
|