(self, import_name: str, exception: BaseException)
| 651 | exception: BaseException |
| 652 | |
| 653 | def __init__(self, import_name: str, exception: BaseException) -> None: |
| 654 | self.import_name = import_name |
| 655 | self.exception = exception |
| 656 | msg = import_name |
| 657 | name = "" |
| 658 | tracked = [] |
| 659 | for part in import_name.replace(":", ".").split("."): |
| 660 | name = f"{name}.{part}" if name else part |
| 661 | imported = import_string(name, silent=True) |
| 662 | if imported: |
| 663 | tracked.append((name, getattr(imported, "__file__", None))) |
| 664 | else: |
| 665 | track = [f"- {n!r} found in {i!r}." for n, i in tracked] |
| 666 | track.append(f"- {name!r} not found.") |
| 667 | track_str = "\n".join(track) |
| 668 | msg = ( |
| 669 | f"import_string() failed for {import_name!r}. Possible reasons" |
| 670 | f" are:\n\n" |
| 671 | "- missing __init__.py in a package;\n" |
| 672 | "- package or module path not included in sys.path;\n" |
| 673 | "- duplicated package or module name taking precedence in" |
| 674 | " sys.path;\n" |
| 675 | "- missing module, class, function or variable;\n\n" |
| 676 | f"Debugged import:\n\n{track_str}\n\n" |
| 677 | f"Original exception:\n\n{type(exception).__name__}: {exception}" |
| 678 | ) |
| 679 | break |
| 680 | |
| 681 | super().__init__(msg) |
| 682 | |
| 683 | def __repr__(self) -> str: |
| 684 | return f"<{type(self).__name__}({self.import_name!r}, {self.exception!r})>" |
nothing calls this directly
no test coverage detected