Skip to content

Commit

Permalink
use custom logic in lieu of imp.find_module to properly follow subimp…
Browse files Browse the repository at this point in the history
…orts. For example sklearn.tree was spuriously treated as a dynamic module.
  • Loading branch information
rodrigofarnhamsc committed Jan 29, 2016
1 parent 4185137 commit d8dd79f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cloudpickle/cloudpickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,16 @@ def save_module(self, obj):
"""
Save a module as an import
"""
mod_name = obj.__name__
path = None

# Use find_module with each piece to follow subimports
# If module is successfully found then it is not a dynamically created module
try:
imp.find_module(obj.__name__)
for part in mod_name.split('.'):
if path is not None:
path = [path]
_, path, _ = imp.find_module(part, path)
is_dynamic = False
except ImportError:
is_dynamic = True
Expand Down

0 comments on commit d8dd79f

Please sign in to comment.