@@ -339,7 +339,7 @@ def check_specs_in_format_call(
339
339
340
340
The core logic for format checking is implemented in this method.
341
341
"""
342
- # print("in format call")
342
+
343
343
assert all (s .key for s in specs ), "Keys must be auto-generated first!"
344
344
replacements = self .find_replacements_in_call (call , [cast (str , s .key ) for s in specs ])
345
345
assert len (replacements ) == len (specs )
@@ -451,8 +451,9 @@ def perform_special_format_checks(
451
451
call ,
452
452
code = codes .STRING_FORMATTING ,
453
453
)
454
- actual_type = get_proper_type (actual_type )
455
- if isinstance (actual_type , NoneType ):
454
+
455
+ a_type = get_proper_type (actual_type )
456
+ if isinstance (a_type , NoneType ):
456
457
# Perform type check of alignment specifiers on None
457
458
if spec .format_spec and any (c in spec .format_spec for c in "<>^" ):
458
459
specifierIndex = - 1
@@ -469,40 +470,6 @@ def perform_special_format_checks(
469
470
call ,
470
471
code = codes .STRING_FORMATTING ,
471
472
)
472
- if spec .format_spec and not self .type_supports_formatting (actual_type ):
473
- self .msg .fail (
474
- f'"{ actual_type } " does not support custom formatting (no __format__ method)' ,
475
- call ,
476
- code = codes .STRING_FORMATTING ,
477
- )
478
-
479
- def type_supports_formatting (self , actual_type : Type ) -> bool :
480
- actual_type = get_proper_type (actual_type )
481
- if isinstance (
482
- actual_type , (NoneType , LiteralType , AnyType , TupleType , TypeType , DeletedType )
483
- ):
484
- return True
485
- if isinstance (actual_type , Instance ):
486
- fullname = actual_type .type .fullname
487
- substring = [
488
- "builtins." ,
489
- "mypy." ,
490
- "mypyc." ,
491
- "typing." ,
492
- "types." ,
493
- "uuid." ,
494
- "pathlib." ,
495
- "_pytest." ,
496
- "inspect." ,
497
- "os." ,
498
- "sys." ,
499
- "re." ,
500
- "collections." ,
501
- ]
502
- for s in substring :
503
- if s in fullname :
504
- return True
505
- return False
506
473
507
474
def find_replacements_in_call (self , call : CallExpr , keys : list [str ]) -> list [Expression ]:
508
475
"""Find replacement expression for every specifier in str.format() call.
0 commit comments