(self, name: str)
| 7854 | raise KeyError(f"Failed lookup: {name}") |
| 7855 | |
| 7856 | def lookup_qualified(self, name: str) -> SymbolTableNode: |
| 7857 | if "." not in name: |
| 7858 | return self.lookup(name) |
| 7859 | else: |
| 7860 | parts = name.split(".") |
| 7861 | n = self.modules[parts[0]] |
| 7862 | for i in range(1, len(parts) - 1): |
| 7863 | sym = n.names.get(parts[i]) |
| 7864 | assert sym is not None, "Internal error: attempted lookup of unknown name" |
| 7865 | assert isinstance(sym.node, MypyFile) |
| 7866 | n = sym.node |
| 7867 | last = parts[-1] |
| 7868 | if last in n.names: |
| 7869 | return n.names[last] |
| 7870 | elif len(parts) == 2 and parts[0] in ("builtins", "typing"): |
| 7871 | fullname = ".".join(parts) |
| 7872 | if fullname in SUGGESTED_TEST_FIXTURES: |
| 7873 | suggestion = ", e.g. add '[{} fixtures/{}]' to your test".format( |
| 7874 | parts[0], SUGGESTED_TEST_FIXTURES[fullname] |
| 7875 | ) |
| 7876 | else: |
| 7877 | suggestion = "" |
| 7878 | raise KeyError( |
| 7879 | "Could not find builtin symbol '{}' (If you are running a " |
| 7880 | "test case, use a fixture that " |
| 7881 | "defines this symbol{})".format(last, suggestion) |
| 7882 | ) |
| 7883 | else: |
| 7884 | msg = "Failed qualified lookup: '{}' (fullname = '{}')." |
| 7885 | raise KeyError(msg.format(last, name)) |
| 7886 | |
| 7887 | @contextmanager |
| 7888 | def enter_partial_types( |
no test coverage detected