Handle 'from module import a, b, c' imports.
(mod, fromlist, buf, recursive)
| 219 | return |
| 220 | |
| 221 | def ensure_fromlist(mod, fromlist, buf, recursive): |
| 222 | """Handle 'from module import a, b, c' imports.""" |
| 223 | if not hasattr(mod, '__path__'): |
| 224 | return |
| 225 | for item in fromlist: |
| 226 | if not hasattr(item, 'rindex'): |
| 227 | raise TypeError("Item in ``from list'' not a string") |
| 228 | if item == '*': |
| 229 | if recursive: |
| 230 | continue # avoid endless recursion |
| 231 | try: |
| 232 | all = mod.__all__ |
| 233 | except AttributeError: |
| 234 | pass |
| 235 | else: |
| 236 | ret = ensure_fromlist(mod, all, buf, 1) |
| 237 | if not ret: |
| 238 | return 0 |
| 239 | elif not hasattr(mod, item): |
| 240 | import_submodule(mod, item, buf + '.' + item) |
| 241 | |
| 242 | def deep_import_hook(name, globals=None, locals=None, fromlist=None, level=-1): |
| 243 | """Replacement for __import__()""" |
no test coverage detected