Issue 22778: list's in-place add doesn't return NotImplemented when appropriate (original) (raw)
Issue22778
Created on 2014-10-31 22:07 by ethan.furman, last changed 2022-04-11 14:58 by admin. This issue is now closed.
Messages (3) | ||
---|---|---|
msg230396 - (view) | Author: Ethan Furman (ethan.furman) * ![]() |
Date: 2014-10-31 22:07 |
--> s = [] --> s += 1 Traceback (most recent call last): File "", line 1, in TypeError: 'int' object is not iterable For comparison, when NotImplemented is appropriately returned the message looks like this: --> s -= 1 Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for -=: 'list' and 'int' Which is certainly more helpful than " object is not iterable" | ||
msg230401 - (view) | Author: Raymond Hettinger (rhettinger) * ![]() |
Date: 2014-10-31 22:20 |
Please don't replicate existing issues. Also, this behavior for lists is long-standing, tested, and designed by Guido. More than a little code relies on this behavior. | ||
msg230408 - (view) | Author: Ethan Furman (ethan.furman) * ![]() |
Date: 2014-10-31 22:43 |
My understanding was that if a different patch will be needed, it is not the same issue. Is that not correct? Here's the test: def test_iadd(self): ... self.assertRaises(TypeError, u.__iadd__, None) It would still pass, as returning NotImplemented will still result in a TypeError, just with a friendlier message. If any code is depending on this, it is depending on the error message text, which is explicitly not guaranteed |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:58:09 | admin | set | github: 66967 |
2014-10-31 22:43:33 | ethan.furman | set | messages: + |
2014-10-31 22:20:20 | rhettinger | set | status: open -> closednosy: + rhettingermessages: + assignee: rhettingerresolution: not a bug |
2014-10-31 22:07:49 | ethan.furman | create |