Handle 'from module import a, b, c' imports.
(mod, fromlist, buf, recursive)
| 203 | return |
| 204 | |
| 205 | def ensure_fromlist(mod, fromlist, buf, recursive): |
| 206 | """Handle 'from module import a, b, c' imports.""" |
| 207 | if not hasattr(mod, '__path__'): |
| 208 | return |
| 209 | for item in fromlist: |
| 210 | if not hasattr(item, 'rindex'): |
| 211 | raise TypeError("Item in ``from list'' not a string") |
| 212 | if item == '*': |
| 213 | if recursive: |
| 214 | continue # avoid endless recursion |
| 215 | try: |
| 216 | all = mod.__all__ |
| 217 | except AttributeError: |
| 218 | pass |
| 219 | else: |
| 220 | ret = ensure_fromlist(mod, all, buf, 1) |
| 221 | if not ret: |
| 222 | return 0 |
| 223 | elif not hasattr(mod, item): |
| 224 | import_submodule(mod, item, buf + '.' + item) |
| 225 | |
| 226 | def deep_import_hook(name, globals=None, locals=None, fromlist=None, level=-1): |
| 227 | """Replacement for __import__()""" |
no test coverage detected
searching dependent graphs…