Fix pickling errors thrown when saving some Stdlib modules#529
Fix pickling errors thrown when saving some Stdlib modules#529mmckerns merged 2 commits intouqfoundation:masterfrom
Conversation
|
@mmckerns: I've been working with module-saving code for months and didn't realize until now that the function >>> import dill
>>> dill.dump_module(module="dill.settings")
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-2-84d05d12f876> in <module>
----> 1 dill.dump_module(module='dill.settings')
~/Projects/forks/dill/dill/session.py in dump_module(filename, module, refimported, refonfail, **kwds)
297 main = _import_module(main)
298 if not isinstance(main, ModuleType):
--> 299 raise TypeError("%r is not a module" % main)
300 original_main = main
301 if refimported:
TypeError: {'protocol': 4, 'byref': False, 'fmode': 0, 'recurse': False, 'ignore': False, 'dump_module': {'refimported': False, 'refonfail': False}} is not a moduleIn this case, the It seems that I'm really confused... By the way, I'm testing the " |
That's great news.
Unfortunately there are a lot of undocumented non-public functions in |
Yes, it seems that there are places where using But take a look at this listing: >>> import dill
>>> dill.__version__
'0.3.5.1'
>>> import importlib
>>> dill_settings = importlib.import_module('dill.settings')
>>> dill_settings
<module 'dill.settings' from '/home/leogama/.local/lib/python3.8/site-packages/dill/settings.py'>
>>> dill.copy(dill_settings)
{'protocol': 4, 'byref': False, 'fmode': 0, 'recurse': False, 'ignore': False}
>>> import pickletools
>>> pickletools.dis(pickletools.optimize(dill.dumps(dill_settings, protocol=0)))
0: c GLOBAL 'dill._dill _import_module'
27: ( MARK
28: V UNICODE 'dill.settings'
43: t TUPLE (MARK at 27)
44: R REDUCE
45: . STOP
highest protocol among opcodes = 0By the way, could you help me with another issue real quick? I'd like to push a commit to Edit: here is the PR: #530 |
I'll add some small pickling errors' fixes here while I test the "save unpickleable objects by reference" option.