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: deque in-place addition does not return NotImplemented when appropriate
Type: behavior Stage: needs patch
Components: Versions: Python 3.5
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: ethan.furman, rhettinger
Priority: low Keywords:

Created on 2014-10-31 22:14 by ethan.furman, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg230397 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2014-10-31 22:14
--> from collections import deque
--> d = deque()
--> d += 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable

deque should be returning NotImplemented, which would generate a more appropriate error message:

TypeError: unsupported operand type(s) for -=: 'collections.deque' and 'int'

which is what happens with -=, *=, /=, |=, at which point I stopped testing.
msg230398 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-10-31 22:15
Please don't replicate the same variant of the issue multiple times.
msg230403 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-10-31 22:23
This behavior was intended.  It was modeled after the behavior for lists.

Any change here would break code such as:

   d = deque()
   d += 'abc'     # This is specially allowed (note, we have a test for it)
Date User Action Args
2022-04-11 14:58:09adminsetgithub: 66968
2014-10-31 22:23:33rhettingersetstatus: open -> closed
resolution: not a bug
messages: + msg230403
2014-10-31 22:15:52rhettingersetmessages: + msg230398
2014-10-31 22:14:36ethan.furmancreate