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

Fix _is_builtin_module #567

Merged
merged 1 commit into from
Dec 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions dill/_dill.py
Original file line number Diff line number Diff line change
Expand Up @@ -1588,10 +1588,18 @@ def _is_builtin_module(module):
# If a module file name starts with prefix, it should be a builtin
# module, so should always be pickled as a reference.
names = ["base_prefix", "base_exec_prefix", "exec_prefix", "prefix", "real_prefix"]
return any(os.path.realpath(module.__file__).startswith(os.path.realpath(getattr(sys, name)))
for name in names if hasattr(sys, name)) or \
module.__file__.endswith(EXTENSION_SUFFIXES) or \
'site-packages' in module.__file__
rp = os.path.realpath
# See https://github.com/uqfoundation/dill/issues/566
return (
any(
module.__file__.startswith(getattr(sys, name))
or rp(module.__file__).startswith(rp(getattr(sys, name)))
for name in names
if hasattr(sys, name)
)
or module.__file__.endswith(EXTENSION_SUFFIXES)
or 'site-packages' in module.__file__
)

def _is_imported_module(module):
return getattr(module, '__loader__', None) is not None or module in sys.modules.values()
Expand Down