This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: list's in-place add doesn't return NotImplemented when appropriate
Type: behavior Stage:
Components: Versions: Python 3.5
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: ethan.furman, rhettinger
Priority: normal Keywords:

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) * (Python committer) Date: 2014-10-31 22:07
--> s = []
--> s += 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
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 "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -=: 'list' and 'int'

Which is certainly more helpful than "<blank> object is not iterable"
msg230401 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) 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) * (Python committer) 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
Date User Action Args
2022-04-11 14:58:09adminsetgithub: 66967
2014-10-31 22:43:33ethan.furmansetmessages: + msg230408
2014-10-31 22:20:20rhettingersetstatus: open -> closed

nosy: + rhettinger
messages: + msg230401

assignee: rhettinger
resolution: not a bug
2014-10-31 22:07:49ethan.furmancreate