MCPcopy Create free account
hub / github.com/ipython/ipython / vformat

Method vformat

IPython/utils/text.py:541–569  ·  view source on GitHub ↗
(self, format_string:str, args, kwargs)

Source from the content-addressed store, hash-verified

539 # copied from Formatter._vformat with minor changes to allow eval
540 # and replace the format_spec code with slicing
541 def vformat(self, format_string:str, args, kwargs)->str:
542 result = []
543 for literal_text, field_name, format_spec, conversion in \
544 self.parse(format_string):
545
546 # output the literal text
547 if literal_text:
548 result.append(literal_text)
549
550 # if there's a field, output it
551 if field_name is not None:
552 # this is some markup, find the object and do
553 # the formatting
554
555 if format_spec:
556 # override format spec, to allow slicing:
557 field_name = ':'.join([field_name, format_spec])
558
559 # eval the contents of the field for the object
560 # to be formatted
561 obj = eval(field_name, kwargs)
562
563 # do any conversion on the resulting object
564 obj = self.convert_field(obj, conversion)
565
566 # format the object and append to the result
567 result.append(self.format_field(obj, ''))
568
569 return ''.join(result)
570
571
572class DollarFormatter(FullEvalFormatter):

Callers 1

var_expandMethod · 0.80

Calls 1

parseMethod · 0.45

Tested by

no test coverage detected