8000 Remove builtin_type by 97littleleaf11 · Pull Request #11214 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Remove builtin_type #11214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Remove lookup_fully_qualified
  • Loading branch information
97littleleaf11 committed Sep 27, 2021
commit 541c278a6909ac862e36c7deaebd816af1a835d1
8 changes: 0 additions & 8 deletions mypy/plugin.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,6 @@ def builtin_type(self, fully_qualified_name: str) -> Instance:
"""Deprecated: use named_type instead."""
raise NotImplementedError

@abstractmethod
def lookup_fully_qualified(self, name: str) -> SymbolTableNode:
"""Lookup a symbol by its fully qualified name.

Raise an error if not found.
"""
raise NotImplementedError

@abstractmethod
def lookup_fully_qualified_or_none(self, name: str) -> Optional[SymbolTableNode]:
"""Lookup a symbol by its fully qualified name.
Expand Down
22 changes: 3 additions & 19 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4362,23 +4362,6 @@ 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_or_none(self, fullname: str) -> Optional[SymbolTableNode]:
"""Lookup a fully qualified name that refers to a module-level definition.
8000
Expand All @@ -4403,7 +4386,8 @@ def lookup_fully_qualified_or_none(self, fullname: str) -> Optional[SymbolTableN
return result

def builtin_type(self, fully_qualified_name: str) -> Instance:
sym = self.lookup_fully_qualified(fully_qualified_name)
sym = self.lookup_fully_qualified_or_none(fully_qualified_name)
assert sym is not None
node = sym.node
assert isinstance(node, TypeInfo)
return Instance(node, [AnyType(TypeOfAny.special_form)] * len(node.defn.type_vars))
Expand Down Expand Up @@ -4550,7 +4534,7 @@ def add_symbol_table_node(self,
if not (isinstance(new, (FuncDef, Decorator))
and self.set_original_def(old, new)):
self.name_already_defined(name, context, existing)
elif (name not in self.missing_names[-1] and '*' not in self.missing_names[-1]):
elif name not in self.missing_names[-1] and '*' not in self.missing_names[-1]:
names[name] = symbol
self.progress = True
return True
Expand Down
4 changes: 0 additions & 4 deletions mypy/semanal_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ def lookup_qualified(self, name: str, ctx: Context,
suppress_errors: bool = False) -> Optional[SymbolTableNode]:
raise NotImplementedError

@abstractmethod
def lookup_fully_qualified(self, name: str) -> SymbolTableNode:
raise NotImplementedError

@abstractmethod
def lookup_fully_qualified_or_none(self, name: str) -> Optional[SymbolTableNode]:
raise NotImplementedError
Expand Down
5 changes: 3 additions & 2 deletions mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def __init__(self,
report_invalid_types: bool = True) -> None:
self.api = api
self.lookup_qualified = api.lookup_qualified
self.lookup_fqn_func = api.lookup_fully_qualified
self.lookup_fqn_func = api.lookup_fully_qualified_or_none
self.fail_func = api.fail
self.note_func = api.note
self.tvar_scope = tvar_scope
Expand Down Expand Up @@ -666,7 +666,7 @@ def visit_type_type(self, t: TypeType) -> Type:
return TypeType.make_normalized(self.anal_type(t.item), line=t.line)

def visit_placeholder_type(self, t: PlaceholderType) -> Type:
n = None if t.fullname is None else self.api.lookup_fully_qualified(t.fullname)
n = None if t.fullname is None else self.api.lookup_fully_qualified_or_none(t.fullname)
if not n or isinstance(n.node, PlaceholderNode):
self.api.defer() # Still incomplete
return t
Expand Down Expand Up @@ -1001,6 +1001,7 @@ def named_type(self, fully_qualified_name: str,
line: int = -1,
column: int = -1) -> Instance:
node = self.lookup_fqn_func(fully_qualified_name)
assert node is not None
assert isinstance(node.node, TypeInfo)
any_type = AnyType(TypeOfAny.special_form)
return Instance(node.node, args or [any_type] * len(node.node.defn.type_vars),
Expand Down
0