save_function()
can't save function in a submodule that has the same name as an attribute of the parent module
#628
Labels
Milestone
Hi,
So if there is a module
test_module/__init__.py
:and then in
test_module/test.py
there is:Then if you
import test_module
then the nametest_module.test
goes to the functiontest_module.test()
instead of the submoduletest_module.test
.If we then try to (dill) pickle either one of the functions it will raise an error:
Any of the above 3 will throw an error:
This is using
dill==0.3.7
and Python 3.11 and on the master branch too f66ed3b, and a repo to reproduce it is: https://github.com/kelvinburke/dill-issueI think this is because the function
_import_module()
returns the functiontest_module.test
instead of the submodule of the same name.I think this can be easily fixed with a check that the
getattr(__import__(module, None, None, [obj]), obj)
returns the right typeSee commit: kelvinburke@228a700
Note I think this is the same problem causing #604 but this a slightly different error and simpler to reproduce.
I will open a PR soon that I think will fix both.
The text was updated successfully, but these errors were encountered: