Skip to content

Direct list-out-of-tuple assignment does not work #125955

@maxpat78

Description

@maxpat78

Bug report

Bug description:

I encountered a TypeError exception in a script and reproduced it in the interactive shell:

>>> t = ([1, 2, 3], [4, 5, 6])
>>> t[0] += [7]
Traceback (most recent call last):
  File "<python-input-10>", line 1, in <module>
    t[0] += [7]
    ~^^^
TypeError: 'tuple' object does not support item assignment
>>> o = t[0]; o += [7]
>>> o
[1, 2, 3, 7, 7]

Not only it raises the unexpected TypeError exception as if operating on a tuple, but the item assignment takes place: number 7 appears twice in the list!

CPython versions tested on:

3.13

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions