spack/var/spack/repos/builtin/packages/py-dill/fix-is-builtin-module.patch
Sam Grayson cab8f795a7
Patch dill._dill._is_builtin_module (#34534)
* Patch dill._dill._is_builtin_module

* Fix style

* Add test
2022-12-14 16:03:03 -07:00

26 lines
1.1 KiB
Diff

--- a/dill/_dill.py
+++ b/dill/_dill.py
@@ -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()