Skip to content

Commit

Permalink
import submodule properly when there is an attribute of the module wi…
Browse files Browse the repository at this point in the history
…th the same name (#629)
  • Loading branch information
kelvinburke authored Jan 14, 2024
1 parent cce8ac7 commit 21bd82b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion dill/_dill.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,9 +1023,12 @@ def _import_module(import_name, safe=False):
items = import_name.split('.')
module = '.'.join(items[:-1])
obj = items[-1]
submodule = getattr(__import__(module, None, None, [obj]), obj)
if isinstance(submodule, (ModuleType, type)):
return submodule
return __import__(import_name, None, None, [obj])
else:
return __import__(import_name)
return getattr(__import__(module, None, None, [obj]), obj)
except (ImportError, AttributeError, KeyError):
if safe:
return None
Expand Down

0 comments on commit 21bd82b

Please sign in to comment.