Skip to content

Dictionary unpacking doesn't create a copy #3227

@malcolmvr

Description

@malcolmvr

With Python, executing the following code:

o = {'a': 1, 'b': 2}
o2 = {**o}
o2['a'] = 3
print(o['a'], o2['a'])

results in (1, 3) being printed.

When compiled with Cython (3,3) is printed.

If the code is changed to:

o = {'a': 1, 'b': 2}
o2 = {**o, 'c': 4} # changed
o2['a'] = 3
print(o['a'], o2['a'])

Then the Cython compiled version behaves the same as the Python-interpreted version. Cython seems to be taking a shortcut and not creating a copy of the object.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions