@@ -419,7 +419,7 @@ def __init__(
419
419
self .expr_checker = mypy .checkexpr .ExpressionChecker (
420
420
self , self .msg , self .plugin , per_line_checking_time_ns
421
421
)
422
- self .pattern_checker = PatternChecker (self , self .msg , self .plugin )
422
+ self .pattern_checker = PatternChecker (self , self .msg , self .plugin , options )
423
423
424
424
@property
425
425
def type_context (self ) -> list [Type | None ]:
@@ -483,7 +483,9 @@ def check_first_pass(self) -> None:
483
483
"typing.Sequence" , [self .named_type ("builtins.str" )]
484
484
)
485
485
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
+ )
487
489
self .fail (
488
490
message_registry .ALL_MUST_BE_SEQ_STR .format (str_seq_s , all_s ), all_node
489
491
)
@@ -1178,7 +1180,8 @@ def check_func_def(
1178
1180
msg = None
1179
1181
elif typ .arg_names [i ] in {"self" , "cls" }:
1180
1182
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 ),
1182
1185
)
1183
1186
else :
1184
1187
msg = message_registry .MISSING_OR_INVALID_SELF_TYPE
@@ -1323,7 +1326,7 @@ def check_unbound_return_typevar(self, typ: CallableType) -> None:
1323
1326
):
1324
1327
self .note (
1325
1328
"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" ,
1327
1330
context = typ .ret_type ,
1328
1331
)
1329
1332
@@ -1430,7 +1433,9 @@ def check___new___signature(self, fdef: FuncDef, typ: CallableType) -> None:
1430
1433
get_proper_type (bound_type .ret_type ), (AnyType , Instance , TupleType , UninhabitedType )
1431
1434
):
1432
1435
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
+ ),
1434
1439
fdef ,
1435
1440
)
1436
1441
else :
@@ -2351,7 +2356,10 @@ class Baz(int, Foo, Bar, enum.Flag): ...
2351
2356
enum_base = base
2352
2357
continue
2353
2358
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
+ )
2355
2363
break
2356
2364
2357
2365
def check_enum_new (self , defn : ClassDef ) -> None :
@@ -2376,7 +2384,7 @@ def has_new_method(info: TypeInfo) -> bool:
2376
2384
if candidate and has_new :
2377
2385
self .fail (
2378
2386
"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 ) ),
2380
2388
defn ,
2381
2389
)
2382
2390
elif candidate :
@@ -3978,7 +3986,12 @@ def check_member_assignment(
3978
3986
3979
3987
dunder_set = attribute_type .type .get_method ("__set__" )
3980
3988
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
+ )
3982
3995
return AnyType (TypeOfAny .from_error ), get_type , False
3983
3996
3984
3997
bound_method = analyze_decorator_or_funcbase_access (
@@ -4132,7 +4145,9 @@ def visit_expression_stmt(self, s: ExpressionStmt) -> None:
4132
4145
if error_note_and_code :
4133
4146
error_note , code = error_note_and_code
4134
4147
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 ,
4136
4151
)
4137
4152
self .note (error_note , s , code = code )
4138
4153
@@ -4962,7 +4977,9 @@ def _make_fake_typeinfo_and_full_name(
4962
4977
# We use the pretty_names_list for error messages but can't
4963
4978
# use it for the real name that goes into the symbol table
4964
4979
# 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
+ )
4966
4983
try :
4967
4984
info , full_name = _make_fake_typeinfo_and_full_name (base_classes , curr_module )
4968
4985
with self .msg .filter_errors () as local_errors :
@@ -4999,7 +5016,7 @@ def intersect_instance_callable(self, typ: Instance, callable_type: CallableType
4999
5016
gen_name = gen_unique_name (f"<callable subtype of { typ .type .name } >" , cur_module .names )
5000
5017
5001
5018
# Synthesize a fake TypeInfo
5002
- short_name = format_type_bare (typ )
5019
+ short_name = format_type_bare (typ , self . options )
5003
5020
cdef , info = self .make_fake_typeinfo (cur_module .fullname , gen_name , short_name , [typ ])
5004
5021
5005
5022
# 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:
5205
5222
return
5206
5223
5207
5224
def format_expr_type () -> str :
5208
- typ = format_type (t )
5225
+ typ = format_type (t , self . options )
5209
5226
if isinstance (expr , MemberExpr ):
5210
5227
return f'Member "{ expr .name } " has type { typ } '
5211
5228
elif isinstance (expr , RefExpr ) and expr .fullname :
@@ -5220,14 +5237,16 @@ def format_expr_type() -> str:
5220
5237
return f"Expression has type { typ } "
5221
5238
5222
5239
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
+ )
5224
5243
elif isinstance (t , UnionType ):
5225
5244
self .fail (message_registry .TYPE_ALWAYS_TRUE_UNIONTYPE .format (format_expr_type ()), expr )
5226
5245
elif isinstance (t , Instance ) and t .type .fullname == "typing.Iterable" :
5227
5246
_ , info = self .make_fake_typeinfo ("typing" , "Collection" , "Collection" , [])
5228
5247
self .fail (
5229
5248
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 )
5231
5250
),
5232
5251
expr ,
5233
5252
)
@@ -6012,7 +6031,9 @@ def check_subtype(
6012
6031
note_msg = ""
6013
6032
notes = notes or []
6014
6033
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
+ )
6016
6037
if subtype_label is not None :
6017
6038
extra_info .append (subtype_label + " " + subtype_str )
6018
6039
if supertype_label is not None :
0 commit comments