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 ,
@@ -697,11 +696,9 @@ def _visit_overloaded_func_def(self, defn: OverloadedFuncDef) -> None:
697
696
assert isinstance (defn .items [0 ], Decorator )
698
697
self .visit_decorator (defn .items [0 ])
699
698
if defn .items [0 ].var .is_settable_property :
700
- # TODO: here and elsewhere we assume setter immediately follows getter.
701
- assert isinstance (defn .items [1 ], Decorator )
702
699
# Perform a reduced visit just to infer the actual setter type.
703
- self .visit_decorator_inner (defn .items [ 1 ] , skip_first_item = True )
704
- setter_type = defn .items [ 1 ] .var .type
700
+ self .visit_decorator_inner (defn .setter , skip_first_item = True )
701
+ setter_type = defn .setter .var .type
705
702
# Check if the setter can accept two positional arguments.
706
703
any_type = AnyType (TypeOfAny .special_form )
707
704
fallback_setter_type = CallableType (
@@ -712,7 +709,7 @@ def _visit_overloaded_func_def(self, defn: OverloadedFuncDef) -> None:
712
709
fallback = self .named_type ("builtins.function" ),
713
710
)
714
711
if setter_type and not is_subtype (setter_type , fallback_setter_type ):
715
- self .fail ("Invalid property setter signature" , defn .items [ 1 ] .func )
712
+ self .fail ("Invalid property setter signature" , defn .setter .func )
716
713
setter_type = self .extract_callable_type (setter_type , defn )
717
714
if not isinstance (setter_type , CallableType ) or len (setter_type .arg_types ) != 2 :
718
715
# TODO: keep precise type for callables with tricky but valid signatures.
@@ -2171,7 +2168,7 @@ def check_setter_type_override(self, defn: OverloadedFuncDef, base: TypeInfo) ->
2171
2168
assert typ is not None and original_type is not None
2172
2169
2173
2170
if not is_subtype (original_type , typ ):
2174
- self .msg .incompatible_setter_override (defn .items [ 1 ] , typ , original_type , base )
2171
+ self .msg .incompatible_setter_override (defn .setter , typ , original_type , base )
2175
2172
2176
2173
def check_method_override_for_base_with_name (
2177
2174
self , defn : FuncDef | OverloadedFuncDef | Decorator , name : str , base : TypeInfo
@@ -2860,29 +2857,6 @@ def check_multiple_inheritance(self, typ: TypeInfo) -> None:
2860
2857
if name in base2 .names and base2 not in base .mro :
2861
2858
self .check_compatibility (name , base , base2 , typ )
2862
2859
2863
- def determine_type_of_member (self , sym : SymbolTableNode ) -> Type | None :
2864
- # TODO: this duplicates both checkmember.py and analyze_ref_expr(), delete.
2865
- if sym .type is not None :
2866
- return sym .type
2867
- if isinstance (sym .node , SYMBOL_FUNCBASE_TYPES ):
2868
- return self .function_type (sym .node )
2869
- if isinstance (sym .node , TypeInfo ):
2870
- if sym .node .typeddict_type :
2871
- # We special-case TypedDict, because they don't define any constructor.
2872
- return self .expr_checker .typeddict_callable (sym .node )
2873
- else :
2874
- return type_object_type (sym .node , self .named_type )
2875
- if isinstance (sym .node , TypeVarExpr ):
2876
- # Use of TypeVars is rejected in an expression/runtime context, so
2877
- # we don't need to check supertype compatibility for them.
2878
- return AnyType (TypeOfAny .special_form )
2879
- if isinstance (sym .node , TypeAlias ):
2880
- with self .msg .filter_errors ():
2881
- # Suppress any errors, they will be given when analyzing the corresponding node.
2882
- # Here we may have incorrect options and location context.
2883
- return self .expr_checker .alias_type_in_runtime_context (sym .node , ctx = sym .node )
2884
- return None
2885
-
2886
2860
def check_compatibility (
2887
2861
self , name : str , base1 : TypeInfo , base2 : TypeInfo , ctx : TypeInfo
2888
2862
) -> None :
@@ -3866,7 +3840,7 @@ def check_assignment_to_multiple_lvalues(
3866
3840
if rvalue_needed > 0 :
3867
3841
rvalues = (
3868
3842
rvalues [0 :iterable_start ]
3869
- + [TempNode (iterable_type ) for i in range (rvalue_needed )]
3843
+ + [TempNode (iterable_type , context = rval ) for _ in range (rvalue_needed )]
3870
3844
+ rvalues [iterable_end + 1 :]
3871
3845
)
3872
3846
@@ -7207,7 +7181,7 @@ def check_subtype(
7207
7181
if extra_info :
7208
7182
msg = msg .with_additional_msg (" (" + ", " .join (extra_info ) + ")" )
7209
7183
7210
- self .fail (msg , context )
7184
+ error = self .fail (msg , context )
7211
7185
for note in notes :
7212
7186
self .msg .note (note , context , code = msg .code )
7213
7187
if note_msg :
@@ -7216,9 +7190,9 @@ def check_subtype(
7216
7190
if (
7217
7191
isinstance (supertype , Instance )
7218
7192
and supertype .type .is_protocol
7219
- and isinstance (subtype , (CallableType , Instance , TupleType , TypedDictType ))
7193
+ and isinstance (subtype , (CallableType , Instance , TupleType , TypedDictType , TypeType ))
7220
7194
):
7221
- self .msg .report_protocol_problems (subtype , supertype , context , code = msg . code )
7195
+ self .msg .report_protocol_problems (subtype , supertype , context , parent_error = error )
7222
7196
if isinstance (supertype , CallableType ) and isinstance (subtype , Instance ):
7223
7197
call = find_member ("__call__" , subtype , subtype , is_operator = True )
7224
7198
if call :
@@ -7547,12 +7521,11 @@ def temp_node(self, t: Type, context: Context | None = None) -> TempNode:
7547
7521
7548
7522
def fail (
7549
7523
self , msg : str | ErrorMessage , context : Context , * , code : ErrorCode | None = None
7550
- ) -> None :
7524
+ ) -> ErrorInfo :
7551
7525
"""Produce an error message."""
7552
7526
if isinstance (msg , ErrorMessage ):
7553
- self .msg .fail (msg .value , context , code = msg .code )
7554
- return
7555
- 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 )
7556
7529
7557
7530
def note (
7558
7531
self ,
0 commit comments