@@ -337,7 +337,7 @@ def has_no_attr(
337
337
self .fail (f'Member "{ member } " is not assignable' , context )
338
338
elif member == "__contains__" :
339
339
self .fail (
340
- "Unsupported right operand type for in ({})" . format ( format_type (original_type )) ,
340
+ f "Unsupported right operand type for in ({ format_type (original_type )} )" ,
341
341
context ,
342
342
code = codes .OPERATOR ,
343
343
)
@@ -350,19 +350,19 @@ def has_no_attr(
350
350
break
351
351
elif member == "__neg__" :
352
352
self .fail (
353
- "Unsupported operand type for unary - ({})" . format ( format_type (original_type )) ,
353
+ f "Unsupported operand type for unary - ({ format_type (original_type )} )" ,
354
354
context ,
355
355
code = codes .OPERATOR ,
356
356
)
357
357
elif member == "__pos__" :
358
358
self .fail (
359
- "Unsupported operand type for unary + ({})" . format ( format_type (original_type )) ,
359
+ f "Unsupported operand type for unary + ({ format_type (original_type )} )" ,
360
360
context ,
361
361
code = codes .OPERATOR ,
362
362
)
363
363
elif member == "__invert__" :
364
364
self .fail (
365
- "Unsupported operand type for ~ ({})" . format ( format_type (original_type )) ,
365
+ f "Unsupported operand type for ~ ({ format_type (original_type )} )" ,
366
366
context ,
367
367
code = codes .OPERATOR ,
368
368
)
@@ -378,7 +378,7 @@ def has_no_attr(
378
378
)
379
379
else :
380
380
self .fail (
381
- "Value of type {} is not indexable" . format ( format_type ( original_type )) ,
381
+ f "Value of type { format_type ( original_type ) } is not indexable" ,
382
382
context ,
383
383
code = codes .INDEX ,
384
384
)
@@ -986,13 +986,13 @@ def no_variant_matches_arguments(
986
986
)
987
987
elif num_args == 1 :
988
988
self .fail (
989
- "No overload variant{} matches argument type {}" . format ( name_str , arg_types_str ) ,
989
+ f "No overload variant{ name_str } matches argument type { arg_types_str } " ,
990
990
context ,
991
991
code = code ,
992
992
)
993
993
else :
994
994
self .fail (
995
- "No overload variant{} matches argument types {}" . format ( name_str , arg_types_str ) ,
995
+ f "No overload variant{ name_str } matches argument types { arg_types_str } " ,
996
996
context ,
997
997
code = code ,
998
998
)
@@ -1009,13 +1009,11 @@ def wrong_number_values_to_unpack(
1009
1009
self .fail (f"Need more than 1 value to unpack ({ expected } expected)" , context )
1010
1010
else :
1011
1011
self .fail (
1012
- "Need more than {} values to unpack ({} expected)" .format (provided , expected ),
1013
- context ,
1012
+ f"Need more than { provided } values to unpack ({ expected } expected)" , context
1014
1013
)
1015
1014
elif provided > expected :
1016
1015
self .fail (
1017
- "Too many values to unpack ({} expected, {} provided)" .format (expected , provided ),
1018
- context ,
1016
+ f"Too many values to unpack ({ expected } expected, { provided } provided)" , context
1019
1017
)
1020
1018
1021
1019
def unpacking_strings_disallowed (self , context : Context ) -> None :
@@ -1035,9 +1033,7 @@ def overload_signature_incompatible_with_supertype(
1035
1033
) -> None :
1036
1034
target = self .override_target (name , name_in_super , supertype )
1037
1035
self .fail (
1038
- 'Signature of "{}" incompatible with {}' .format (name , target ),
1039
- context ,
1040
- code = codes .OVERRIDE ,
1036
+ f'Signature of "{ name } " incompatible with { target } ' , context , code = codes .OVERRIDE
1041
1037
)
1042
1038
1043
1039
note_template = 'Overload variants must be defined in the same order as they are in "{}"'
@@ -1054,9 +1050,7 @@ def signature_incompatible_with_supertype(
1054
1050
) -> None :
1055
1051
code = codes .OVERRIDE
1056
1052
target = self .override_target (name , name_in_super , supertype )
1057
- self .fail (
1058
- 'Signature of "{}" incompatible with {}' .format (name , target ), context , code = code
1059
- )
1053
+ self .fail (f'Signature of "{ name } " incompatible with { target } ' , context , code = code )
1060
1054
1061
1055
INCLUDE_DECORATOR = True # Include @classmethod and @staticmethod decorators, if any
1062
1056
ALLOW_DUPS = True # Allow duplicate notes, needed when signatures are duplicates
@@ -1197,13 +1191,11 @@ def incompatible_type_application(
1197
1191
self .fail ("Type application targets a non-generic function or class" , context )
1198
1192
elif actual_arg_count > expected_arg_count :
1199
1193
self .fail (
1200
- "Type application has too many types ({} expected)" .format (expected_arg_count ),
1201
- context ,
1194
+ f"Type application has too many types ({ expected_arg_count } expected)" , context
1202
1195
)
1203
1196
else :
1204
1197
self .fail (
1205
- "Type application has too few types ({} expected)" .format (expected_arg_count ),
1206
- context ,
1198
+ f"Type application has too few types ({ expected_arg_count } expected)" , context
1207
1199
)
1208
1200
1209
1201
def could_not_infer_type_arguments (
@@ -1487,9 +1479,7 @@ def forward_operator_not_callable(self, forward_method: str, context: Context) -
1487
1479
self .fail (f'Forward operator "{ forward_method } " is not callable' , context )
1488
1480
1489
1481
def signatures_incompatible (self , method : str , other_method : str , context : Context ) -> None :
1490
- self .fail (
1491
- 'Signatures of "{}" and "{}" are incompatible' .format (method , other_method ), context
1492
- )
1482
+ self .fail (f'Signatures of "{ method } " and "{ other_method } " are incompatible' , context )
1493
1483
1494
1484
def yield_from_invalid_operand_type (self , expr : Type , context : Context ) -> Type :
1495
1485
text = format_type (expr ) if format_type (expr ) != "object" else expr
@@ -1641,7 +1631,7 @@ def typeddict_key_not_found(
1641
1631
)
1642
1632
else :
1643
1633
self .fail (
1644
- 'TypedDict {} has no key "{}"' . format ( format_type ( typ ), item_name ) ,
1634
+ f 'TypedDict { format_type ( typ ) } has no key "{ item_name } "' ,
1645
1635
context ,
1646
1636
code = codes .TYPEDDICT_ITEM ,
1647
1637
)
@@ -1655,9 +1645,7 @@ def typeddict_key_not_found(
1655
1645
1656
1646
def typeddict_context_ambiguous (self , types : List [TypedDictType ], context : Context ) -> None :
1657
1647
formatted_types = ", " .join (list (format_type_distinctly (* types )))
1658
- self .fail (
1659
- "Type of TypedDict is ambiguous, could be any of ({})" .format (formatted_types ), context
1660
- )
1648
+ self .fail (f"Type of TypedDict is ambiguous, could be any of ({ formatted_types } )" , context )
1661
1649
1662
1650
def typeddict_key_cannot_be_deleted (
1663
1651
self , typ : TypedDictType , item_name : str , context : Context
@@ -1666,8 +1654,7 @@ def typeddict_key_cannot_be_deleted(
1666
1654
self .fail (f'TypedDict key "{ item_name } " cannot be deleted' , context )
1667
1655
else :
1668
1656
self .fail (
1669
- 'Key "{}" of TypedDict {} cannot be deleted' .format (item_name , format_type (typ )),
1670
- context ,
1657
+ f'Key "{ item_name } " of TypedDict { format_type (typ )} cannot be deleted' , context
1671
1658
)
1672
1659
1673
1660
def typeddict_setdefault_arguments_inconsistent (
@@ -1719,8 +1706,7 @@ def untyped_decorated_function(self, typ: Type, context: Context) -> None:
1719
1706
self .fail ("Function is untyped after decorator transformation" , context )
1720
1707
else :
1721
1708
self .fail (
1722
- 'Type of decorated function contains type "Any" ({})' .format (format_type (typ )),
1723
- context ,
1709
+ f'Type of decorated function contains type "Any" ({ format_type (typ )} )' , context
1724
1710
)
1725
1711
1726
1712
def typed_function_untyped_decorator (self , func_name : str , context : Context ) -> None :
@@ -1739,14 +1725,12 @@ def bad_proto_variance(
1739
1725
1740
1726
def concrete_only_assign (self , typ : Type , context : Context ) -> None :
1741
1727
self .fail (
1742
- "Can only assign concrete classes to a variable of type {}" .format (format_type (typ )),
1743
- context ,
1728
+ f"Can only assign concrete classes to a variable of type { format_type (typ )} " , context
1744
1729
)
1745
1730
1746
1731
def concrete_only_call (self , typ : Type , context : Context ) -> None :
1747
1732
self .fail (
1748
- "Only concrete class can be given where {} is expected" .format (format_type (typ )),
1749
- context ,
1733
+ f"Only concrete class can be given where { format_type (typ )} is expected" , context
1750
1734
)
1751
1735
1752
1736
def cannot_use_function_with_type (
@@ -1763,7 +1747,7 @@ def report_non_method_protocol(
1763
1747
)
1764
1748
if len (members ) < 3 :
1765
1749
attrs = ", " .join (members )
1766
- self .note ('Protocol "{}" has non-method member(s): {}' . format ( tp . name , attrs ) , context )
1750
+ self .note (f 'Protocol "{ tp . name } " has non-method member(s): { attrs } ' , context )
1767
1751
1768
1752
def note_call (
1769
1753
self , subtype : Type , call : Type , context : Context , * , code : Optional [ErrorCode ]
@@ -2117,9 +2101,7 @@ def format_callable_args(
2117
2101
if arg_kind .is_star () or arg_name is None :
2118
2102
arg_strings .append (f"{ constructor } ({ format (arg_type )} )" )
2119
2103
else :
2120
- arg_strings .append (
2121
- "{}({}, {})" .format (constructor , format (arg_type ), repr (arg_name ))
2122
- )
2104
+ arg_strings .append (f"{ constructor } ({ format (arg_type )} , { repr (arg_name )} )" )
2123
2105
2124
2106
return ", " .join (arg_strings )
2125
2107
0 commit comments