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)
| 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 |