MCPcopy Index your code
hub / github.com/python/mypy / check_str_format_call

Method check_str_format_call

mypy/checkstrformat.py:305–331  ·  view source on GitHub ↗

Perform more precise checks for str.format() calls when possible. Currently the checks are performed for: * Actual string literals * Literal types with string values * Final names with string values The checks that we currently perform: * Che

(self, call: CallExpr, format_value: str)

Source from the content-addressed store, hash-verified

303 self.msg = msg
304
305 def check_str_format_call(self, call: CallExpr, format_value: str) -> None:
306 """Perform more precise checks for str.format() calls when possible.
307
308 Currently the checks are performed for:
309 * Actual string literals
310 * Literal types with string values
311 * Final names with string values
312
313 The checks that we currently perform:
314 * Check generic validity (e.g. unmatched { or }, and {} in invalid positions)
315 * Check consistency of specifiers' auto-numbering
316 * Verify that replacements can be found for all conversion specifiers,
317 and all arguments were used
318 * Non-standard format specs are only allowed for types with custom __format__
319 * Type check replacements with accessors applied (if any).
320 * Verify that specifier type is known and matches replacement type
321 * Perform special checks for some specifier types:
322 - 'c' requires a single character string
323 - 's' must not accept bytes
324 - non-empty flags are only allowed for numeric types
325 """
326 conv_specs = parse_format_value(format_value, call, self.msg)
327 if conv_specs is None:
328 return
329 if not self.auto_generate_keys(conv_specs, call):
330 return
331 self.check_specs_in_format_call(call, conv_specs, format_value)
332
333 def check_specs_in_format_call(
334 self, call: CallExpr, specs: list[ConversionSpecifier], format_value: str

Callers

nothing calls this directly

Calls 3

auto_generate_keysMethod · 0.95
parse_format_valueFunction · 0.85

Tested by

no test coverage detected