Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment:

It is how PEP 584 specifies it. The in-place operator is more lenient.

It corresponds the behavior of list operators.

>>> x = []
>>> y = (1, 2)
>>> x + y
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can only concatenate list (not "tuple") to list
>>> x += y
>>> x
[1, 2]

But on other hand, the in-place operator of set is more restrictive:

>>> x = set()
>>> x |= (1, 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for |=: 'set' and 'tuple'

Should not we make "|=" for dict and "+=" for list more restrictive? I heard 
that it was considered a mistake in list to accept arbitrary iterables.

----------
nosy: +serhiy.storchaka

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39806>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to