From 071a3853479878caf5bc1921505ac96e20cd1ed8 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Fri, 7 Jan 2022 14:05:59 +0000 Subject: [PATCH] Restore removed builtin_type() api method 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: https://github.com/dropbox/sqlalchemy-stubs/issues/232 --- mypy/plugin.py | 6 ++++++ mypy/semanal.py | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/mypy/plugin.py b/mypy/plugin.py index 3772d7039b05..201ec65748b9 100644 --- a/mypy/plugin.py +++ b/mypy/plugin.py @@ -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]: diff --git a/mypy/semanal.py b/mypy/semanal.py index aca1f545c472..764fb4c36394 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -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)