@@ -419,7 +419,7 @@ def __init__(
419419 self .expr_checker = mypy .checkexpr .ExpressionChecker (
420420 self , self .msg , self .plugin , per_line_checking_time_ns
421421 )
422- self .pattern_checker = PatternChecker (self , self .msg , self .plugin )
422+ self .pattern_checker = PatternChecker (self , self .msg , self .plugin , options )
423423
424424 @property
425425 def type_context (self ) -> list [Type | None ]:
@@ -483,7 +483,9 @@ def check_first_pass(self) -> None:
483483 "typing.Sequence" , [self .named_type ("builtins.str" )]
484484 )
485485 if not is_subtype (all_ .type , seq_str ):
486- str_seq_s , all_s = format_type_distinctly (seq_str , all_ .type )
486+ str_seq_s , all_s = format_type_distinctly (
487+ seq_str , all_ .type , options = self .options
488+ )
487489 self .fail (
488490 message_registry .ALL_MUST_BE_SEQ_STR .format (str_seq_s , all_s ), all_node
489491 )
@@ -1178,7 +1180,8 @@ def check_func_def(
11781180 msg = None
11791181 elif typ .arg_names [i ] in {"self" , "cls" }:
11801182 msg = message_registry .ERASED_SELF_TYPE_NOT_SUPERTYPE .format (
1181- erased , ref_type
1183+ erased .str_with_options (self .options ),
1184+ ref_type .str_with_options (self .options ),
11821185 )
11831186 else :
11841187 msg = message_registry .MISSING_OR_INVALID_SELF_TYPE
@@ -1323,7 +1326,7 @@ def check_unbound_return_typevar(self, typ: CallableType) -> None:
13231326 ):
13241327 self .note (
13251328 "Consider using the upper bound "
1326- f"{ format_type (typ .ret_type .upper_bound )} instead" ,
1329+ f"{ format_type (typ .ret_type .upper_bound , self . options )} instead" ,
13271330 context = typ .ret_type ,
13281331 )
13291332
@@ -1430,7 +1433,9 @@ def check___new___signature(self, fdef: FuncDef, typ: CallableType) -> None:
14301433 get_proper_type (bound_type .ret_type ), (AnyType , Instance , TupleType , UninhabitedType )
14311434 ):
14321435 self .fail (
1433- message_registry .NON_INSTANCE_NEW_TYPE .format (format_type (bound_type .ret_type )),
1436+ message_registry .NON_INSTANCE_NEW_TYPE .format (
1437+ format_type (bound_type .ret_type , self .options )
1438+ ),
14341439 fdef ,
14351440 )
14361441 else :
@@ -2351,7 +2356,10 @@ class Baz(int, Foo, Bar, enum.Flag): ...
23512356 enum_base = base
23522357 continue
23532358 elif enum_base is not None and not base .type .is_enum :
2354- self .fail (f'No non-enum mixin classes are allowed after "{ enum_base } "' , defn )
2359+ self .fail (
2360+ f'No non-enum mixin classes are allowed after "{ enum_base .str_with_options (self .options )} "' ,
2361+ defn ,
2362+ )
23552363 break
23562364
23572365 def check_enum_new (self , defn : ClassDef ) -> None :
@@ -2376,7 +2384,7 @@ def has_new_method(info: TypeInfo) -> bool:
23762384 if candidate and has_new :
23772385 self .fail (
23782386 "Only a single data type mixin is allowed for Enum subtypes, "
2379- 'found extra "{}"' .format (base ),
2387+ 'found extra "{}"' .format (base . str_with_options ( self . options ) ),
23802388 defn ,
23812389 )
23822390 elif candidate :
@@ -3978,7 +3986,12 @@ def check_member_assignment(
39783986
39793987 dunder_set = attribute_type .type .get_method ("__set__" )
39803988 if dunder_set is None :
3981- self .fail (message_registry .DESCRIPTOR_SET_NOT_CALLABLE .format (attribute_type ), context )
3989+ self .fail (
3990+ message_registry .DESCRIPTOR_SET_NOT_CALLABLE .format (
3991+ attribute_type .str_with_options (self .options )
3992+ ),
3993+ context ,
3994+ )
39823995 return AnyType (TypeOfAny .from_error ), get_type , False
39833996
39843997 bound_method = analyze_decorator_or_funcbase_access (
@@ -4132,7 +4145,9 @@ def visit_expression_stmt(self, s: ExpressionStmt) -> None:
41324145 if error_note_and_code :
41334146 error_note , code = error_note_and_code
41344147 self .fail (
4135- message_registry .TYPE_MUST_BE_USED .format (format_type (expr_type )), s , code = code
4148+ message_registry .TYPE_MUST_BE_USED .format (format_type (expr_type , self .options )),
4149+ s ,
4150+ code = code ,
41364151 )
41374152 self .note (error_note , s , code = code )
41384153
@@ -4962,7 +4977,9 @@ def _make_fake_typeinfo_and_full_name(
49624977 # We use the pretty_names_list for error messages but can't
49634978 # use it for the real name that goes into the symbol table
49644979 # because it can have dots in it.
4965- pretty_names_list = pretty_seq (format_type_distinctly (* base_classes , bare = True ), "and" )
4980+ pretty_names_list = pretty_seq (
4981+ format_type_distinctly (* base_classes , options = self .options , bare = True ), "and"
4982+ )
49664983 try :
49674984 info , full_name = _make_fake_typeinfo_and_full_name (base_classes , curr_module )
49684985 with self .msg .filter_errors () as local_errors :
@@ -4999,7 +5016,7 @@ def intersect_instance_callable(self, typ: Instance, callable_type: CallableType
49995016 gen_name = gen_unique_name (f"<callable subtype of { typ .type .name } >" , cur_module .names )
50005017
50015018 # Synthesize a fake TypeInfo
5002- short_name = format_type_bare (typ )
5019+ short_name = format_type_bare (typ , self . options )
50035020 cdef , info = self .make_fake_typeinfo (cur_module .fullname , gen_name , short_name , [typ ])
50045021
50055022 # Build up a fake FuncDef so we can populate the symbol table.
@@ -5205,7 +5222,7 @@ def _check_for_truthy_type(self, t: Type, expr: Expression) -> None:
52055222 return
52065223
52075224 def format_expr_type () -> str :
5208- typ = format_type (t )
5225+ typ = format_type (t , self . options )
52095226 if isinstance (expr , MemberExpr ):
52105227 return f'Member "{ expr .name } " has type { typ } '
52115228 elif isinstance (expr , RefExpr ) and expr .fullname :
@@ -5220,14 +5237,16 @@ def format_expr_type() -> str:
52205237 return f"Expression has type { typ } "
52215238
52225239 if isinstance (t , FunctionLike ):
5223- self .fail (message_registry .FUNCTION_ALWAYS_TRUE .format (format_type (t )), expr )
5240+ self .fail (
5241+ message_registry .FUNCTION_ALWAYS_TRUE .format (format_type (t , self .options )), expr
5242+ )
52245243 elif isinstance (t , UnionType ):
52255244 self .fail (message_registry .TYPE_ALWAYS_TRUE_UNIONTYPE .format (format_expr_type ()), expr )
52265245 elif isinstance (t , Instance ) and t .type .fullname == "typing.Iterable" :
52275246 _ , info = self .make_fake_typeinfo ("typing" , "Collection" , "Collection" , [])
52285247 self .fail (
52295248 message_registry .ITERABLE_ALWAYS_TRUE .format (
5230- format_expr_type (), format_type (Instance (info , t .args ))
5249+ format_expr_type (), format_type (Instance (info , t .args ), self . options )
52315250 ),
52325251 expr ,
52335252 )
@@ -6012,7 +6031,9 @@ def check_subtype(
60126031 note_msg = ""
60136032 notes = notes or []
60146033 if subtype_label is not None or supertype_label is not None :
6015- subtype_str , supertype_str = format_type_distinctly (orig_subtype , orig_supertype )
6034+ subtype_str , supertype_str = format_type_distinctly (
6035+ orig_subtype , orig_supertype , options = self .options
6036+ )
60166037 if subtype_label is not None :
60176038 extra_info .append (subtype_label + " " + subtype_str )
60186039 if supertype_label is not None :
0 commit comments