@@ -60,7 +60,7 @@ def __init__(self,
60
60
self .chk = chk
61
61
self .module_symbol_table = module_symbol_table
62
62
63
- def builtin_type (self , name : str ) -> Instance :
63
+ def named_type (self , name : str ) -> Instance :
64
64
return self .chk .named_type (name )
65
65
66
66
def not_ready_callback (self , name : str , context : Context ) -> None :
@@ -202,7 +202,7 @@ def analyze_instance_member_access(name: str,
202
202
return analyze_var (name , first_item .var , typ , info , mx )
203
203
if mx .is_lvalue :
204
204
mx .msg .cant_assign_to_method (mx .context )
205
- signature = function_type (method , mx .builtin_type ('builtins.function' ))
205
+ signature = function_type (method , mx .named_type ('builtins.function' ))
206
206
signature = freshen_function_type_vars (signature )
207
207
if name == '__new__' :
208
208
# __new__ is special and behaves like a static method -- don't strip
@@ -266,7 +266,7 @@ def analyze_type_type_member_access(name: str,
266
266
override_info : Optional [TypeInfo ]) -> Type :
267
267
# Similar to analyze_type_callable_attribute_access.
268
268
item = None
269
- fallback = mx .builtin_type ('builtins.type' )
269
+ fallback = mx .named_type ('builtins.type' )
270
270
ignore_messages = mx .msg .copy ()
271
271
ignore_messages .disable_errors ().__enter__ ()
272
272
if isinstance (typ .item , Instance ):
@@ -326,10 +326,10 @@ def analyze_none_member_access(name: str, typ: NoneType, mx: MemberContext) -> T
326
326
return CallableType (arg_types = [],
327
327
arg_kinds = [],
328
328
arg_names = [],
329
- ret_type = mx .builtin_type ('builtins.bool' ),
330
- fallback = mx .builtin_type ('builtins.function' ))
329
+ ret_type = mx .named_type ('builtins.bool' ),
330
+ fallback = mx .named_type ('builtins.function' ))
331
331
else :
332
- return _analyze_member_access (name , mx .builtin_type ('builtins.object' ), mx )
332
+ return _analyze_member_access (name , mx .named_type ('builtins.object' ), mx )
333
333
334
334
335
335
def analyze_member_var_access (name : str ,
@@ -354,7 +354,7 @@ def analyze_member_var_access(name: str,
354
354
# If the associated variable is a TypeInfo synthesize a Var node for
355
355
# the purposes of type checking. This enables us to type check things
356
356
# like accessing class attributes on an inner class.
357
- v = Var (name , type = type_object_type (vv , mx .builtin_type ))
357
+ v = Var (name , type = type_object_type (vv , mx .named_type ))
358
358
v .info = info
359
359
360
360
if isinstance (vv , TypeAlias ) and isinstance (get_proper_type (vv .target ), Instance ):
@@ -364,7 +364,7 @@ def analyze_member_var_access(name: str,
364
364
# class C:
365
365
# A = List[int]
366
366
# x = C.A() <- this is OK
367
- typ = instance_alias_type (vv , mx .builtin_type )
367
+ typ = instance_alias_type (vv , mx .named_type )
368
368
v = Var (name , type = typ )
369
369
v .info = info
370
370
@@ -388,7 +388,7 @@ def analyze_member_var_access(name: str,
388
388
# the guard this search will always find object.__getattribute__ and conclude
389
389
# that the attribute exists
390
390
if method and method .info .fullname != 'builtins.object' :
391
- function = function_type (method , mx .builtin_type ('builtins.function' ))
391
+ function = function_type (method , mx .named_type ('builtins.function' ))
392
392
bound_method = bind_self (function , mx .self_type )
393
393
typ = map_instance_to_supertype (itype , method .info )
394
394
getattr_type = get_proper_type (expand_type_by_instance (bound_method , typ ))
@@ -405,7 +405,7 @@ def analyze_member_var_access(name: str,
405
405
else :
406
406
setattr_meth = info .get_method ('__setattr__' )
407
407
if setattr_meth and setattr_meth .info .fullname != 'builtins.object' :
408
- setattr_func = function_type (setattr_meth , mx .builtin_type ('builtins.function' ))
408
+ setattr_func = function_type (setattr_meth , mx .named_type ('builtins.function' ))
409
409
bound_type = bind_self (setattr_func , mx .self_type )
410
410
typ = map_instance_to_supertype (itype , setattr_meth .info )
411
411
setattr_type = get_proper_type (expand_type_by_instance (bound_type , typ ))
@@ -615,7 +615,7 @@ def analyze_var(name: str,
615
615
fullname = '{}.{}' .format (var .info .fullname , name )
616
616
hook = mx .chk .plugin .get_attribute_hook (fullname )
617
617
if result and not mx .is_lvalue and not implicit :
618
- result = analyze_descriptor_access (mx .original_type , result , mx .builtin_type ,
618
+ result = analyze_descriptor_access (mx .original_type , result , mx .named_type ,
619
619
mx .msg , mx .context , chk = mx .chk )
620
620
if hook :
621
621
result = hook (AttributeContext (get_proper_type (mx .original_type ),
@@ -792,7 +792,7 @@ def analyze_class_attribute_access(itype: Instance,
792
792
result = add_class_tvars (t , isuper , is_classmethod ,
793
793
mx .self_type , original_vars = original_vars )
794
794
if not mx .is_lvalue :
795
- result = analyze_descriptor_access (mx .original_type , result , mx .builtin_type ,
795
+ result = analyze_descriptor_access (mx .original_type , result , mx .named_type ,
796
796
mx .msg , mx .context , chk = mx .chk )
797
797
return result
798
798
elif isinstance (node .node , Var ):
@@ -805,15 +805,15 @@ def analyze_class_attribute_access(itype: Instance,
805
805
return AnyType (TypeOfAny .from_error )
806
806
807
807
if isinstance (node .node , TypeInfo ):
808
- return type_object_type (node .node , mx .builtin_type )
808
+ return type_object_type (node .node , mx .named_type )
809
809
810
810
if isinstance (node .node , MypyFile ):
811
811
# Reference to a module object.
812
- return mx .builtin_type ('types.ModuleType' )
812
+ return mx .named_type ('types.ModuleType' )
813
813
814
814
if (isinstance (node .node , TypeAlias ) and
815
815
isinstance (get_proper_type (node .node .target ), Instance )):
816
- return instance_alias_type (node .node , mx .builtin_type )
816
+ return instance_alias_type (node .node , mx .named_type )
817
817
818
818
if is_decorated :
819
819
assert isinstance (node .node , Decorator )
@@ -824,7 +824,7 @@ def analyze_class_attribute_access(itype: Instance,
824
824
return AnyType (TypeOfAny .from_error )
825
825
else :
826
826
assert isinstance (node .node , FuncBase )
827
- typ = function_type (node .node , mx .builtin_type ('builtins.function' ))
827
+ typ = function_type (node .node , mx .named_type ('builtins.function' ))
828
828
# Note: if we are accessing class method on class object, the cls argument is bound.
829
829
# Annotated and/or explicit class methods go through other code paths above, for
830
830
# unannotated implicit class methods we do this here.
@@ -913,7 +913,7 @@ class B(A[str]): pass
913
913
return t
914
914
915
915
916
- def type_object_type (info : TypeInfo , builtin_type : Callable [[str ], Instance ]) -> ProperType :
916
+ def type_object_type (info : TypeInfo , named_type : Callable [[str ], Instance ]) -> ProperType :
917
917
"""Return the type of a type object.
918
918
919
919
For a generic type G with type variables T and S the type is generally of form
@@ -945,7 +945,7 @@ def type_object_type(info: TypeInfo, builtin_type: Callable[[str], Instance]) ->
945
945
init_index = info .mro .index (init_method .node .info )
946
946
new_index = info .mro .index (new_method .node .info )
947
947
948
- fallback = info .metaclass_type or builtin_type ('builtins.type' )
948
+ fallback = info .metaclass_type or named_type ('builtins.type' )
949
949
if init_index < new_index :
950
950
method : Union [FuncBase , Decorator ] = init_method .node
951
951
is_new = False
@@ -963,7 +963,7 @@ def type_object_type(info: TypeInfo, builtin_type: Callable[[str], Instance]) ->
963
963
arg_kinds = [ARG_STAR , ARG_STAR2 ],
964
964
arg_names = ["_args" , "_kwds" ],
965
965
ret_type = any_type ,
966
- fallback = builtin_type ('builtins.function' ))
966
+ fallback = named_type ('builtins.function' ))
967
967
return class_callable (sig , info , fallback , None , is_new = False )
968
968
969
969
# Otherwise prefer __init__ in a tie. It isn't clear that this
0 commit comments