| 486 | # copied from Formatter._vformat with minor changes to allow eval |
| 487 | # and replace the format_spec code with slicing |
| 488 | def vformat( |
| 489 | self, format_string: str, args: Sequence[Any], kwargs: Mapping[str, Any] |
| 490 | ) -> str: |
| 491 | result = [] |
| 492 | conversion: Optional[str] |
| 493 | for literal_text, field_name, format_spec, conversion in self.parse( |
| 494 | format_string |
| 495 | ): |
| 496 | # output the literal text |
| 497 | if literal_text: |
| 498 | result.append(literal_text) |
| 499 | |
| 500 | # if there's a field, output it |
| 501 | if field_name is not None: |
| 502 | # this is some markup, find the object and do |
| 503 | # the formatting |
| 504 | |
| 505 | if format_spec: |
| 506 | # override format spec, to allow slicing: |
| 507 | field_name = ':'.join([field_name, format_spec]) |
| 508 | |
| 509 | # eval the contents of the field for the object |
| 510 | # to be formatted |
| 511 | obj = eval(field_name, dict(kwargs)) |
| 512 | |
| 513 | # do any conversion on the resulting object |
| 514 | # type issue in typeshed, fined in https://github.com/python/typeshed/pull/11377 |
| 515 | obj = self.convert_field(obj, conversion) |
| 516 | |
| 517 | # format the object and append to the result |
| 518 | result.append(self.format_field(obj, '')) |
| 519 | |
| 520 | return ''.join(result) |
| 521 | |
| 522 | |
| 523 | class DollarFormatter(FullEvalFormatter): |