MCPcopy
hub / github.com/django/django / import_string

Function import_string

django/utils/module_loading.py:19–35  ·  view source on GitHub ↗

Import a dotted module path and return the attribute/class designated by the last name in the path. Raise ImportError if the import failed.

(dotted_path)

Source from the content-addressed store, hash-verified

17
18
19def import_string(dotted_path):
20 """
21 Import a dotted module path and return the attribute/class designated by
22 the last name in the path. Raise ImportError if the import failed.
23 """
24 try:
25 module_path, class_name = dotted_path.rsplit(".", 1)
26 except ValueError as err:
27 raise ImportError("%s doesn't look like a module path" % dotted_path) from err
28
29 try:
30 return cached_import(module_path, class_name)
31 except AttributeError as err:
32 raise ImportError(
33 'Module "%s" does not define a "%s" attribute/class'
34 % (module_path, class_name)
35 ) from err
36
37
38def autodiscover_modules(*args, **kwargs):

Callers 15

__init__Method · 0.90
get_finderFunction · 0.90
load_backendFunction · 0.90
get_hashersFunction · 0.90
get_password_validatorsFunction · 0.90
_subclass_indexFunction · 0.90
default_storageFunction · 0.90
_setupMethod · 0.90
_contains_subclassFunction · 0.90
configure_loggingFunction · 0.90
__init__Method · 0.90
get_cookie_signerFunction · 0.90

Calls 1

cached_importFunction · 0.85

Tested by 2

test_import_stringMethod · 0.72
test_module_pathMethod · 0.72