Taken from pydantic.utils.
(dotted_path: str)
| 136 | |
| 137 | |
| 138 | def import_string(dotted_path: str) -> Any: |
| 139 | """ |
| 140 | Taken from pydantic.utils. |
| 141 | """ |
| 142 | from importlib import import_module |
| 143 | |
| 144 | try: |
| 145 | module_path, class_name = dotted_path.strip(' ').rsplit('.', 1) |
| 146 | except ValueError as e: |
| 147 | raise ImportError(f'"{dotted_path}" doesn\'t look like a module path') from e |
| 148 | |
| 149 | module = import_module(module_path) |
| 150 | try: |
| 151 | return getattr(module, class_name) |
| 152 | except AttributeError as e: |
| 153 | raise ImportError(f'Module "{module_path}" does not define a "{class_name}" attribute') from e |