@@ -476,8 +476,6 @@ def incompatible_argument(self,
476476
477477 target = 'to {} ' .format (name )
478478
479- msg = ''
480- code = codes .MISC
481479 notes : List [str ] = []
482480 if callee_name == '<list>' :
483481 name = callee_name [1 :- 1 ]
@@ -564,19 +562,23 @@ def incompatible_argument(self,
564562 expected_type ,
565563 bare = True )
566564 arg_label = '"{}"' .format (arg_name )
565+ object_type = get_proper_type (object_type )
567566 if isinstance (outer_context , IndexExpr ) and isinstance (outer_context .index , StrExpr ):
568- msg = message_registry .VALUE_INCOMPATIBLE_TYPE .format (
567+ if isinstance (object_type , TypedDictType ):
568+ msg = message_registry .TYPEDDICT_VALUE_INCOMPATIBLE_TYPE
569+ else :
570+ msg = message_registry .VALUE_INCOMPATIBLE_TYPE
571+ msg = msg .format (
569572 outer_context .index .value , quote_type_string (arg_type_str ),
570573 quote_type_string (expected_type_str ))
571574 else :
572- msg = message_registry .ARGUMENT_INCOMPATIBLE_TYPE .format (
575+ if isinstance (object_type , TypedDictType ):
576+ msg = message_registry .TYPEDDICT_ARGUMENT_INCOMPATIBLE_TYPE
577+ else :
578+ msg = message_registry .ARGUMENT_INCOMPATIBLE_TYPE
579+ msg = msg .format (
573580 arg_label , target , quote_type_string (arg_type_str ),
574581 quote_type_string (expected_type_str ))
575- object_type = get_proper_type (object_type )
576- if isinstance (object_type , TypedDictType ):
577- code = codes .TYPEDDICT_ITEM
578- else :
579- code = codes .ARG_TYPE
580582 expected_type = get_proper_type (expected_type )
581583 if isinstance (expected_type , UnionType ):
582584 expected_types = list (expected_type .items )
@@ -588,7 +590,7 @@ def incompatible_argument(self,
588590 self .fail (msg , context )
589591 if notes :
590592 for note_msg in notes :
591- self .note (note_msg , context , code = code )
593+ self .note (note_msg , context , code = msg . code )
592594 return msg .code
593595
594596 def incompatible_argument_note (self ,
@@ -1058,7 +1060,7 @@ def incompatible_typevar_value(self,
10581060 context : Context ) -> None :
10591061 self .fail (message_registry .INCOMPATIBLE_TYPEVAR_VALUE
10601062 .format (typevar_name , callable_name (callee ) or 'function' , format_type (typ )),
1061- context )
1063+ context , code = codes . TYPE_VAR ) # TODO: migrate with TypeVar messages
10621064
10631065 def dangerous_comparison (self , left : Type , right : Type , kind : str , ctx : Context ) -> None :
10641066 left_str = 'element' if kind == 'container' else 'left operand'
@@ -1231,7 +1233,7 @@ def typeddict_key_not_found(
12311233 matches = best_matches (item_name , typ .items .keys ())
12321234 if matches :
12331235 self .note ("Did you mean {}?" .format (
1234- pretty_seq (matches [:3 ], "or" )), context )
1236+ pretty_seq (matches [:3 ], "or" )), context , code = codes . TYPEDDICT_ITEM )
12351237
12361238 def typeddict_context_ambiguous (
12371239 self ,
0 commit comments