Skip to content

add logic to convert dict list key to tuple #633

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jensbjorgensen
Copy link

Python dictionaries with tuples as a key can be packed, however when they are unpacked an error occurs because the key
comes back as a list rather than a tuple, although it's possible to set at the top-level use_list=False this is undesirable as
it affects everything. This solution is slightly wasteful as it results in a list being created and then converted to a tuple however it has the advantage of being the smallest change to the code that makes this work.

Comment on lines +532 to +533
if isinstance(key, list):
key = tuple(key)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is tuple the only data type that is valid as a dict key and that would come back as a list after pack/unpack?

Nitpick: use elif

@@ -199,6 +199,25 @@ static inline int unpack_callback_map_item(unpack_user* u, unsigned int current,
if (PyUnicode_CheckExact(k)) {
PyUnicode_InternInPlace(&k);
}
if (PyList_CheckExact(k)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: use else if

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants