-
Notifications
You must be signed in to change notification settings - Fork 176
Add pickling of dict_keys, dict_values, dict_items #384
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
Changes from all commits
40fb0cb
9d23203
16fa5e8
d5a74ec
7d38355
4e45b1b
0742b53
8eb737c
6715661
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -828,3 +828,15 @@ def _get_bases(typ): | |
# For regular class objects | ||
bases_attr = '__bases__' | ||
return getattr(typ, bases_attr) | ||
|
||
|
||
def _make_dict_keys(obj): | ||
return dict.fromkeys(obj).keys() | ||
|
||
|
||
def _make_dict_values(obj): | ||
return {i: _ for i, _ in enumerate(obj)}.values() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar comment here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While I am not sure of any particular special properties of dict_values objects, I think the approach taken here should mirror the approach taken with dict_keys. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. |
||
|
||
|
||
def _make_dict_items(obj): | ||
return obj.items() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure it's worth rebuilding a fake dict with
None
valued values. Maybe we could just ship the list of keys and values directly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One reason not to leave these as just a list of keys is that dict_keys objects are set-like and support set type operations: https://docs.python.org/3/tutorial/datastructures.html#dictionaries
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point.