[issue22766] collections.Counter's in-place operators should return NotImplemented for unsupported types

Antoine Pitrou report at bugs.python.org
Fri Oct 31 23:23:13 CET 2014


Antoine Pitrou added the comment:

I think I've changed my mind on this. The important distinction is not between "ducktyping" or "cooperating". It's that this is an in-place mutating operation. A mutating operation should always be the responsibility of the receiver, and so it sounds wrong to be able to delegate it to the read-only operand.

For example, when calling list.extend(op), the list object doesn't allow `op` to take over the operation's semantics. So I think TypeError is the right outcome here.

----------

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


More information about the Python-bugs-list mailing list