Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dictionary unpacking doesn't create a copy #3227

malcolmvr opened this issue Nov 8, 2019 · 0 comments


Copy link

@malcolmvr malcolmvr commented Nov 8, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
1 participant
You can’t perform that action at this time.