Skip to content

Commit cfc6b17

Browse files
Fix merge conflicts
2 parents 693486e + e3d002e commit cfc6b17

File tree

1 file changed

+4
-37
lines changed

1 file changed

+4
-37
lines changed

mypy/checkstrformat.py

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def check_specs_in_format_call(
339339
340340
The core logic for format checking is implemented in this method.
341341
"""
342-
# print("in format call")
342+
343343
assert all(s.key for s in specs), "Keys must be auto-generated first!"
344344
replacements = self.find_replacements_in_call(call, [cast(str, s.key) for s in specs])
345345
assert len(replacements) == len(specs)
@@ -451,8 +451,9 @@ def perform_special_format_checks(
451451
call,
452452
code=codes.STRING_FORMATTING,
453453
)
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):
456457
# Perform type check of alignment specifiers on None
457458
if spec.format_spec and any(c in spec.format_spec for c in "<>^"):
458459
specifierIndex = -1
@@ -469,40 +470,6 @@ def perform_special_format_checks(
469470
call,
470471
code=codes.STRING_FORMATTING,
471472
)
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
506473

507474
def find_replacements_in_call(self, call: CallExpr, keys: list[str]) -> list[Expression]:
508475
"""Find replacement expression for every specifier in str.format() call.

0 commit comments

Comments
 (0)