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

Method auto_generate_keys

mypy/checkstrformat.py:541–568  ·  view source on GitHub ↗

Translate '{} {name} {}' to '{0} {name} {1}'. Return True if generation was successful, otherwise report an error and return false.

(self, all_specs: list[ConversionSpecifier], ctx: Context)

Source from the content-addressed store, hash-verified

539 return TempNode(map_instance_to_supertype(kwargs_type, mapping_info).args[1])
540
541 def auto_generate_keys(self, all_specs: list[ConversionSpecifier], ctx: Context) -> bool:
542 """Translate '{} {name} {}' to '{0} {name} {1}'.
543
544 Return True if generation was successful, otherwise report an error and return false.
545 """
546 some_defined = any(s.key and s.key.isdecimal() for s in all_specs)
547 all_defined = all(bool(s.key) for s in all_specs)
548 if some_defined and not all_defined:
549 self.msg.fail(
550 "Cannot combine automatic field numbering and manual field specification",
551 ctx,
552 code=codes.STRING_FORMATTING,
553 )
554 return False
555 if all_defined:
556 return True
557 next_index = 0
558 for spec in all_specs:
559 if not spec.key:
560 str_index = str(next_index)
561 spec.key = str_index
562 # Update also the full field (i.e. turn {.x} into {0.x}).
563 if not spec.field:
564 spec.field = str_index
565 else:
566 spec.field = str_index + spec.field
567 next_index += 1
568 return True
569
570 def apply_field_accessors(
571 self, spec: ConversionSpecifier, repl: Expression, ctx: Context

Callers 1

check_str_format_callMethod · 0.95

Calls 5

anyFunction · 0.85
allFunction · 0.85
boolClass · 0.85
strClass · 0.85
failMethod · 0.45

Tested by

no test coverage detected