Check the types of the 'replacements' in a string interpolation expression: str % replacements.
(self, expr: FormatStringExpr, replacements: Expression)
| 674 | # TODO: In Python 3, the bytes formatting has a more restricted set of options |
| 675 | # compared to string formatting. |
| 676 | def check_str_interpolation(self, expr: FormatStringExpr, replacements: Expression) -> Type: |
| 677 | """Check the types of the 'replacements' in a string interpolation |
| 678 | expression: str % replacements. |
| 679 | """ |
| 680 | self.chk.expr_checker.accept(expr) |
| 681 | specifiers = parse_conversion_specifiers(expr.value) |
| 682 | has_mapping_keys = self.analyze_conversion_specifiers(specifiers, expr) |
| 683 | if has_mapping_keys is None: |
| 684 | pass # Error was reported |
| 685 | elif has_mapping_keys: |
| 686 | self.check_mapping_str_interpolation(specifiers, replacements, expr) |
| 687 | else: |
| 688 | self.check_simple_str_interpolation(specifiers, replacements, expr) |
| 689 | |
| 690 | if isinstance(expr, BytesExpr): |
| 691 | return self.named_type("builtins.bytes") |
| 692 | elif isinstance(expr, StrExpr): |
| 693 | return self.named_type("builtins.str") |
| 694 | else: |
| 695 | assert False |
| 696 | |
| 697 | def analyze_conversion_specifiers( |
| 698 | self, specifiers: list[ConversionSpecifier], context: Context |
no test coverage detected