Skip to content
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

Behavior and use cases of _import_module() is unclear #533

Open
leogama opened this issue Aug 1, 2022 · 0 comments
Open

Behavior and use cases of _import_module() is unclear #533

leogama opened this issue Aug 1, 2022 · 0 comments

Comments

@leogama
Copy link
Contributor

leogama commented Aug 1, 2022

It seems that _import_module() works much more like Unpickler.find_class() than like importlib.import_module()

Unfortunately there are a lot of undocumented non-public functions in dill. However, you can see from the code that it does import the module (or submodule), so it's an appropriate name... it's just not the dill equivalent of importlib.import_module().

Yes, it seems that there are places where using importlib.import_module() is more appropriate than _import_module().

Take a look at this listing, it doesn't look right:

>>> 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 = 0

I think we should compare the API and implementation of this function with the ones of pickle._Unpickler.find_class(), importlib.import_module() and even logging.config._resolve() that I recently found out.

Originally posted by @leogama in #529 (comment)

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

No branches or pull requests

1 participant