Simplify splitting import_name in import_string()

This commit is contained in:
Min ho Kim 2019-07-24 09:55:04 +10:00
parent 9a877fa6c7
commit 486a2f4afa

View File

@ -136,9 +136,7 @@ def import_string(import_name, silent=False):
if ':' in import_name:
module, obj = import_name.split(':', 1)
elif '.' in import_name:
items = import_name.split('.')
module = '.'.join(items[:-1])
obj = items[-1]
module, _, obj = import_name.rpartition('.')
else:
return __import__(import_name)
return getattr(__import__(module, None, None, [obj]), obj)