Get named replacement expression from '{name}'.format(name=...) call. If the type is from **kwargs, return TempNode( ). Return None in case of an error.
(self, key: str, call: CallExpr)
| 512 | return TempNode(map_instance_to_supertype(varargs_type, iter_info).args[0]) |
| 513 | |
| 514 | def get_expr_by_name(self, key: str, call: CallExpr) -> Expression | None: |
| 515 | """Get named replacement expression from '{name}'.format(name=...) call. |
| 516 | |
| 517 | If the type is from **kwargs, return TempNode(<item type>). Return None in case of |
| 518 | an error. |
| 519 | """ |
| 520 | named_args = [ |
| 521 | arg |
| 522 | for arg, kind, name in zip(call.args, call.arg_kinds, call.arg_names) |
| 523 | if kind == ARG_NAMED and name == key |
| 524 | ] |
| 525 | if named_args: |
| 526 | return named_args[0] |
| 527 | star_args_2 = [arg for arg, kind in zip(call.args, call.arg_kinds) if kind == ARG_STAR2] |
| 528 | if not star_args_2: |
| 529 | return None |
| 530 | star_arg_2 = star_args_2[0] |
| 531 | kwargs_type = get_proper_type(self.chk.lookup_type(star_arg_2)) |
| 532 | if not isinstance(kwargs_type, Instance) or not kwargs_type.type.has_base( |
| 533 | "typing.Mapping" |
| 534 | ): |
| 535 | # Error should be already reported. |
| 536 | return TempNode(AnyType(TypeOfAny.special_form)) |
| 537 | any_type = AnyType(TypeOfAny.special_form) |
| 538 | mapping_info = self.chk.named_generic_type("typing.Mapping", [any_type, any_type]).type |
| 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}'. |
no test coverage detected