Skip to content

Commit 116d00b

Browse files
97littleleaf11tushar-deepsource
authored andcommitted
Discard deprecated builtin_type (python#11343)
Related to python#6578. builtin_type could be totally replaced with named_type after python#11332. Also renames other builtin_type for consistency since all of them are actually calling named_type.
1 parent 29310ac commit 116d00b

File tree

8 files changed

+17
-28
lines changed

8 files changed

+17
-28
lines changed

mypy/checkmember.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ def check_final_member(name: str, info: TypeInfo, msg: MessageBuilder, ctx: Cont
438438

439439
def analyze_descriptor_access(instance_type: Type,
440440
descriptor_type: Type,
441-
builtin_type: Callable[[str], Instance],
441+
named_type: Callable[[str], Instance],
442442
msg: MessageBuilder,
443443
context: Context, *,
444444
chk: 'mypy.checker.TypeChecker') -> Type:
@@ -460,7 +460,7 @@ def analyze_descriptor_access(instance_type: Type,
460460
if isinstance(descriptor_type, UnionType):
461461
# Map the access over union types
462462
return make_simplified_union([
463-
analyze_descriptor_access(instance_type, typ, builtin_type,
463+
analyze_descriptor_access(instance_type, typ, named_type,
464464
msg, context, chk=chk)
465465
for typ in descriptor_type.items
466466
])
@@ -476,7 +476,7 @@ def analyze_descriptor_access(instance_type: Type,
476476
msg.fail(message_registry.DESCRIPTOR_GET_NOT_CALLABLE.format(descriptor_type), context)
477477
return AnyType(TypeOfAny.from_error)
478478

479-
function = function_type(dunder_get, builtin_type('builtins.function'))
479+
function = function_type(dunder_get, named_type('builtins.function'))
480480
bound_method = bind_self(function, descriptor_type)
481481
typ = map_instance_to_supertype(descriptor_type, dunder_get.info)
482482
dunder_get_type = expand_type_by_instance(bound_method, typ)
@@ -518,7 +518,7 @@ def analyze_descriptor_access(instance_type: Type,
518518

519519

520520
def instance_alias_type(alias: TypeAlias,
521-
builtin_type: Callable[[str], Instance]) -> Type:
521+
named_type: Callable[[str], Instance]) -> Type:
522522
"""Type of a type alias node targeting an instance, when appears in runtime context.
523523
524524
As usual, we first erase any unbound type variables to Any.
@@ -528,7 +528,7 @@ def instance_alias_type(alias: TypeAlias,
528528
Instance), "Must be called only with aliases to classes"
529529
target = get_proper_type(set_any_tvars(alias, alias.line, alias.column))
530530
assert isinstance(target, Instance)
531-
tp = type_object_type(target.type, builtin_type)
531+
tp = type_object_type(target.type, named_type)
532532
return expand_type_by_instance(tp, target)
533533

534534

mypy/plugin.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,6 @@ def class_type(self, self_type: Type) -> Type:
297297
"""Generate type of first argument of class methods from type of self."""
298298
raise NotImplementedError
299299

300-
@abstractmethod
301-
def builtin_type(self, fully_qualified_name: str) -> Instance:
302-
"""Deprecated: use named_type instead."""
303-
raise NotImplementedError
304-
305300
@abstractmethod
306301
def lookup_fully_qualified(self, name: str) -> SymbolTableNode:
307302
"""Lookup a symbol by its fully qualified name.

mypy/plugins/attrs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def argument(self, ctx: 'mypy.plugin.ClassDefContext') -> Argument:
9797
converter_type: Optional[Type] = None
9898
if converter and isinstance(converter.node, TypeInfo):
9999
from mypy.checkmember import type_object_type # To avoid import cycle.
100-
converter_type = type_object_type(converter.node, ctx.api.builtin_type)
100+
converter_type = type_object_type(converter.node, ctx.api.named_type)
101101
elif converter and isinstance(converter.node, OverloadedFuncDef):
102102
converter_type = converter.node.type
103103
elif converter and converter.type:

mypy/semanal.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ def analyze_overloaded_func_def(self, defn: OverloadedFuncDef) -> None:
732732
# This is a property.
733733
first_item.func.is_overload = True
734734
self.analyze_property_with_multi_part_definition(defn)
735-
typ = function_type(first_item.func, self.builtin_type('builtins.function'))
735+
typ = function_type(first_item.func, self.named_type('builtins.function'))
736736
assert isinstance(typ, CallableType)
737737
types = [typ]
738738
else:
@@ -789,7 +789,7 @@ def analyze_overload_sigs_and_impl(
789789
item.accept(self)
790790
# TODO: support decorated overloaded functions properly
791791
if isinstance(item, Decorator):
792-
callable = function_type(item.func, self.builtin_type('builtins.function'))
792+
callable = function_type(item.func, self.named_type('builtins.function'))
793793
assert isinstance(callable, CallableType)
794794
if not any(refers_to_fullname(dec, 'typing.overload')
795795
for dec in item.decorators):
@@ -4421,12 +4421,6 @@ def lookup_fully_qualified_or_none(self, fullname: str) -> Optional[SymbolTableN
44214421
self.record_incomplete_ref()
44224422
return result
44234423

4424-
def builtin_type(self, fully_qualified_name: str) -> Instance:
4425-
sym = self.lookup_fully_qualified(fully_qualified_name)
4426-
node = sym.node
4427-
assert isinstance(node, TypeInfo)
4428-
return Instance(node, [AnyType(TypeOfAny.special_form)] * len(node.defn.type_vars))
4429-
44304424
def object_type(self) -> Instance:
44314425
return self.named_type('builtins.object')
44324426

mypy/suggestions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def get_trivial_type(self, fdef: FuncDef) -> CallableType:
288288
fdef.arg_kinds,
289289
fdef.arg_names,
290290
AnyType(TypeOfAny.suggestion_engine),
291-
self.builtin_type('builtins.function'))
291+
self.named_type('builtins.function'))
292292

293293
def get_starting_type(self, fdef: FuncDef) -> CallableType:
294294
if isinstance(fdef.type, CallableType):
@@ -351,7 +351,7 @@ def get_default_arg_types(self, state: State, fdef: FuncDef) -> List[Optional[Ty
351351
def add_adjustments(self, typs: List[Type]) -> List[Type]:
352352
if not self.try_text or self.manager.options.python_version[0] != 2:
353353
return typs
354-
translator = StrToText(self.builtin_type)
354+
translator = StrToText(self.named_type)
355355
return dedup(typs + [tp.accept(translator) for tp in typs])
356356

357357
def get_guesses(self, is_method: bool, base: CallableType, defaults: List[Optional[Type]],
@@ -648,8 +648,8 @@ def ensure_loaded(self, state: State, force: bool = False) -> MypyFile:
648648
assert state.tree is not None
649649
return state.tree
650650

651-
def builtin_type(self, s: str) -> Instance:
652-
return self.manager.semantic_analyzer.builtin_type(s)
651+
def named_type(self, s: str) -> Instance:
652+
return self.manager.semantic_analyzer.named_type(s)
653653

654654
def json_suggestion(self, mod: str, func_name: str, node: FuncDef,
655655
suggestion: PyAnnotateSignature) -> str:
@@ -850,8 +850,8 @@ def visit_callable_type(self, t: CallableType) -> str:
850850

851851

852852
class StrToText(TypeTranslator):
853-
def __init__(self, builtin_type: Callable[[str], Instance]) -> None:
854-
self.text_type = builtin_type('builtins.unicode')
853+
def __init__(self, named_type: Callable[[str], Instance]) -> None:
854+
self.text_type = named_type('builtins.unicode')
855855

856856
def visit_type_alias_type(self, t: TypeAliasType) -> Type:
857857
exp_t = get_proper_type(t)

test-data/unit/plugins/common_api_incremental.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def add_info_hook(ctx) -> None:
2424

2525
info = TypeInfo(SymbolTable(), class_def, ctx.api.cur_mod_id)
2626
class_def.info = info
27-
obj = ctx.api.builtin_type('builtins.object')
27+
obj = ctx.api.named_type('builtins.object')
2828
info.mro = [info, obj.type]
2929
info.bases = [obj]
3030
ctx.api.add_symbol_table_node(ctx.name, SymbolTableNode(GDEF, info))

test-data/unit/plugins/dyn_class.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def add_info_hook(ctx):
2323

2424
info = TypeInfo(SymbolTable(), class_def, ctx.api.cur_mod_id)
2525
class_def.info = info
26-
obj = ctx.api.builtin_type('builtins.object')
26+
obj = ctx.api.named_type('builtins.object')
2727
info.mro = [info, obj.type]
2828
info.bases = [obj]
2929
ctx.api.add_symbol_table_node(ctx.name, SymbolTableNode(GDEF, info))

test-data/unit/plugins/dyn_class_from_method.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def add_info_hook(ctx: DynamicClassDefContext):
1818
class_def.info = info
1919
queryset_type_fullname = ctx.call.args[0].fullname
2020
queryset_info = ctx.api.lookup_fully_qualified_or_none(queryset_type_fullname).node # type: TypeInfo
21-
obj = ctx.api.builtin_type('builtins.object')
21+
obj = ctx.api.named_type('builtins.object')
2222
info.mro = [info, queryset_info, obj.type]
2323
info.bases = [Instance(queryset_info, [])]
2424
ctx.api.add_symbol_table_node(ctx.name, SymbolTableNode(GDEF, info))

0 commit comments

Comments
 (0)