MCPcopy Index your code
hub / github.com/RustPython/RustPython / format

Method format

Lib/test/test_peepholer.py:721–727  ·  view source on GitHub ↗
(fmt, *values)

Source from the content-addressed store, hash-verified

719
720 def test_format_misc(self):
721 def format(fmt, *values):
722 vars = [f'x{i+1}' for i in range(len(values))]
723 if len(vars) == 1:
724 args = '(' + vars[0] + ',)'
725 else:
726 args = '(' + ', '.join(vars) + ')'
727 return eval(f'{fmt!r} % {args}', dict(zip(vars, values)))
728
729 self.assertEqual(format('string'), 'string')
730 self.assertEqual(format('x = %s!', 1234), 'x = 1234!')

Calls 3

lenFunction · 0.85
evalFunction · 0.50
joinMethod · 0.45

Tested by

no test coverage detected