From d1d431630d967923a9562b4dff436a509c2acb8b Mon Sep 17 00:00:00 2001 From: 97littleleaf11 <97littleleaf11@users.noreply.github.com> Date: Wed, 6 Oct 2021 00:03:13 +0800 Subject: [PATCH] Merge lookup_fully_qualified and lookup_fully_qualified_or_none (#11205) Partially solves #4157 --- mypy/semanal.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/mypy/semanal.py b/mypy/semanal.py index 49c24cde0447..496215eea80f 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -4362,22 +4362,10 @@ def create_getattr_var(self, getattr_defn: SymbolTableNode, return v return None - def lookup_fully_qualified(self, name: str) -> SymbolTableNode: - """Lookup a fully qualified name. - - Assume that the name is defined. This happens in the global namespace -- - the local module namespace is ignored. - - Note that this doesn't support visibility, module-level __getattr__, or - nested classes. - """ - parts = name.split('.') - n = self.modules[parts[0]] - for i in range(1, len(parts) - 1): - next_sym = n.names[parts[i]] - assert isinstance(next_sym.node, MypyFile) - n = next_sym.node - return n.names[parts[-1]] + def lookup_fully_qualified(self, fullname: str) -> SymbolTableNode: + ret = self.lookup_fully_qualified_or_none(fullname) + assert ret is not None + return ret def lookup_fully_qualified_or_none(self, fullname: str) -> Optional[SymbolTableNode]: """Lookup a fully qualified name that refers to a module-level definition.