Skip to content

Support dict views and functools.lru_cache#449

Merged
mmckerns merged 2 commits intouqfoundation:masterfrom
anivegesana:dict_views
Apr 19, 2022
Merged

Support dict views and functools.lru_cache#449
mmckerns merged 2 commits intouqfoundation:masterfrom
anivegesana:dict_views

Conversation

@anivegesana
Copy link
Copy Markdown
Contributor

@anivegesana anivegesana commented Jan 27, 2022

  1. Implement save functions for dictionary view objects and LRU caches
  2. Add trick to extract the dictionary directly from a types.MappingProxyType in CPython 3.9+
  3. Use trick to preserve reference structure for dictionary view objects in Python 3.10+

Fixes #353

Copy link
Copy Markdown
Member

@mmckerns mmckerns left a comment

Choose a reason for hiding this comment

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

LGTM

@mmckerns mmckerns merged commit 914d47f into uqfoundation:master Apr 19, 2022
@anivegesana
Copy link
Copy Markdown
Contributor Author

anivegesana commented Apr 20, 2022

A kind of unrelated side note (can definitely be ignored until after the release and is probably unimportant since I don't think anyone complained about it), but I think a handful of classes are missing from _reverse_typemap. Should I add them to the dictionary and what naming scheme should I give them? These are the classes in CPython. In PyPy, most of the iterators are handled by just two classes: sequenceiterator and reversesequenceiterator, so there will be duplicates in the map.

x=collections.OrderedDict()


"bytes_iterator": type(iter(b'')),
"bytearray_iterator": type(iter(bytearray(b''))),
"callable_iterator": type(iter(iter, None)),
"memory_iterator": type(iter(memoryview(b''))),
"range_iterator": type(iter(range(3))),
"set_iterator": type(iter(set())),
"tuple_iterator": type(iter(())),

"dict_keys": type({}.keys()),
"dict_values": type({}.values()),
"dict_items": type({}.items()),

"dict_keyiterator": type(iter({}.keys())),
"dict_reversekeyiterator": type(reversed({}.keys())),
"dict_valueiterator": type(iter({}.values())),
"dict_reversevalueiterator": type(reversed({}.values())),
"dict_itemiterator": type(iter({}.items())),
"dict_reverseitemiterator": type(reversed({}.items())),

"list_iterator": type(iter([])),
"list_reverseiterator": type(reversed([])),

"odict_keys": type(x.keys()),
"odict_values": type(x.values()),
"odict_items": type(x.items()),

"odict_iterator": iter(x.keys()),

if CPython: "symtable_stentry_type": type(symtable.symtable("", "string", "exec")._table),

if sys.hexversion >= 0x30a00a?: 'line_iterator': type(compile('3', '', 'eval').co_lines()),

if sys.hexversion >= 0x30b00a?: "generic_alias_iterator": type(iter(types.GenericAlias(list, (int,)))),

if sys.hexversion >= 0x30b00a?: 'positions_iterator': type(compile('3', '', 'eval').co_positions()),

if Windows: "PyHKEY": winreg.HKEYType,

@mmckerns
Copy link
Copy Markdown
Member

A kind of unrelated side note...

@anivegesana: Feel free to open a new issue for the above comment. I'm sure that I've missed adding types to the reverse typemap over the years, so it will be good to add any that I've left out. I generally try to use a name that is similar to whatever name the type identifies itself as. You can see a bunch of examples in dill/_objects.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot pickle dict_items, dict_keys & dict_values on Python-3

2 participants