25
25
from mypy .constraints import SUPERTYPE_OF
26
26
from mypy .erasetype import erase_type , erase_typevars , remove_instance_last_known_values
27
27
from mypy .errorcodes import TYPE_VAR , UNUSED_AWAITABLE , UNUSED_COROUTINE , ErrorCode
28
- from mypy .errors import Errors , ErrorWatcher , LoopErrorWatcher , report_internal_error
28
+ from mypy .errors import ErrorInfo , Errors , ErrorWatcher , LoopErrorWatcher , report_internal_error
29
29
from mypy .expandtype import expand_type
30
30
from mypy .literals import Key , extract_var_from_literal_hash , literal , literal_hash
31
31
from mypy .maptype import map_instance_to_supertype
117
117
TypeAlias ,
118
118
TypeAliasStmt ,
119
119
TypeInfo ,
120
- TypeVarExpr ,
121
120
UnaryExpr ,
122
121
Var ,
123
122
WhileStmt ,
@@ -2858,29 +2857,6 @@ def check_multiple_inheritance(self, typ: TypeInfo) -> None:
2858
2857
if name in base2 .names and base2 not in base .mro :
2859
2858
self .check_compatibility (name , base , base2 , typ )
2860
2859
2861
- def determine_type_of_member (self , sym : SymbolTableNode ) -> Type | None :
2862
- # TODO: this duplicates both checkmember.py and analyze_ref_expr(), delete.
2863
- if sym .type is not None :
2864
- return sym .type
2865
- if isinstance (sym .node , SYMBOL_FUNCBASE_TYPES ):
2866
- return self .function_type (sym .node )
2867
- if isinstance (sym .node , TypeInfo ):
2868
- if sym .node .typeddict_type :
2869
- # We special-case TypedDict, because they don't define any constructor.
2870
- return self .expr_checker .typeddict_callable (sym .node )
2871
- else :
2872
- return type_object_type (sym .node , self .named_type )
2873
- if isinstance (sym .node , TypeVarExpr ):
2874
- # Use of TypeVars is rejected in an expression/runtime context, so
2875
- # we don't need to check supertype compatibility for them.
2876
- return AnyType (TypeOfAny .special_form )
2877
- if isinstance (sym .node , TypeAlias ):
2878
- with self .msg .filter_errors ():
2879
- # Suppress any errors, they will be given when analyzing the corresponding node.
2880
- # Here we may have incorrect options and location context.
2881
- return self .expr_checker .alias_type_in_runtime_context (sym .node , ctx = sym .node )
2882
- return None
2883
-
2884
2860
def check_compatibility (
2885
2861
self , name : str , base1 : TypeInfo , base2 : TypeInfo , ctx : TypeInfo
2886
2862
) -> None :
@@ -3864,7 +3840,7 @@ def check_assignment_to_multiple_lvalues(
3864
3840
if rvalue_needed > 0 :
3865
3841
rvalues = (
3866
3842
rvalues [0 :iterable_start ]
3867
- + [TempNode (iterable_type ) for i in range (rvalue_needed )]
3843
+ + [TempNode (iterable_type , context = rval ) for _ in range (rvalue_needed )]
3868
3844
+ rvalues [iterable_end + 1 :]
3869
3845
)
3870
3846
@@ -7205,7 +7181,7 @@ def check_subtype(
7205
7181
if extra_info :
7206
7182
msg = msg .with_additional_msg (" (" + ", " .join (extra_info ) + ")" )
7207
7183
7208
- self .fail (msg , context )
7184
+ error = self .fail (msg , context )
7209
7185
for note in notes :
7210
7186
self .msg .note (note , context , code = msg .code )
7211
7187
if note_msg :
@@ -7214,9 +7190,9 @@ def check_subtype(
7214
7190
if (
7215
7191
isinstance (supertype , Instance )
7216
7192
and supertype .type .is_protocol
7217
- and isinstance (subtype , (CallableType , Instance , TupleType , TypedDictType ))
7193
+ and isinstance (subtype , (CallableType , Instance , TupleType , TypedDictType , TypeType ))
7218
7194
):
7219
- self .msg .report_protocol_problems (subtype , supertype , context , code = msg . code )
7195
+ self .msg .report_protocol_problems (subtype , supertype , context , parent_error = error )
7220
7196
if isinstance (supertype , CallableType ) and isinstance (subtype , Instance ):
7221
7197
call = find_member ("__call__" , subtype , subtype , is_operator = True )
7222
7198
if call :
@@ -7545,12 +7521,11 @@ def temp_node(self, t: Type, context: Context | None = None) -> TempNode:
7545
7521
7546
7522
def fail (
7547
7523
self , msg : str | ErrorMessage , context : Context , * , code : ErrorCode | None = None
7548
- ) -> None :
7524
+ ) -> ErrorInfo :
7549
7525
"""Produce an error message."""
7550
7526
if isinstance (msg , ErrorMessage ):
7551
- self .msg .fail (msg .value , context , code = msg .code )
7552
- return
7553
- self .msg .fail (msg , context , code = code )
7527
+ return self .msg .fail (msg .value , context , code = msg .code )
7528
+ return self .msg .fail (msg , context , code = code )
7554
7529
7555
7530
def note (
7556
7531
self ,
0 commit comments