Skip to content

Commit

Permalink
Fix _is_builtin_module (#567)
Browse files Browse the repository at this point in the history
  • Loading branch information
charmoniumQ committed Dec 15, 2022
1 parent cde66d2 commit 72ffcfb
Showing 1 changed file with 12 additions and 4 deletions.
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

0 comments on commit 72ffcfb

Please sign in to comment.