Skip to content

Commit

Permalink
Restore removed builtin_type() api method
Browse files Browse the repository at this point in the history
It shouldn't be used for new code, but adding it back makes it
unnecessary to update existing plugins that no longer worked with mypy
0.930.

Related issue: dropbox/sqlalchemy-stubs#232
  • Loading branch information
JukkaL committed Jan 7, 2022
1 parent e40877d commit 071a385
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mypy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ def named_type(self, fullname: str,
"""Construct an instance of a builtin type with given type arguments."""
raise NotImplementedError

@abstractmethod
def builtin_type(self, fully_qualified_name: str) -> Instance:
"""Legacy function -- use named_type() instead."""
# NOTE: Do not delete this since many plugins may still use it.
raise NotImplementedError

@abstractmethod
def named_type_or_none(self, fullname: str,
args: Optional[List[Type]] = None) -> Optional[Instance]:
Expand Down
4 changes: 4 additions & 0 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4567,6 +4567,10 @@ def named_type_or_none(self, fullname: str,
return Instance(node, args)
return Instance(node, [AnyType(TypeOfAny.unannotated)] * len(node.defn.type_vars))

def builtin_type(self, fully_qualified_name: str) -> Instance:
"""Legacy function -- use named_type() instead."""
return self.named_type(fully_qualified_name)

def lookup_current_scope(self, name: str) -> Optional[SymbolTableNode]:
if self.locals[-1] is not None:
return self.locals[-1].get(name)
Expand Down

0 comments on commit 071a385

Please sign in to comment.