New submission from Ross Biro <[email protected]>:
The only point in the string.Formatter class that really depends on string
output is line 245: return ''.join(result), auto_arg_index.
I'm currently working on a problem that would be much easier if I could get
access to the result list instead of having that join called.
I propose creating another overridable method in string.Formatter, say oformat
that calls _vformat and is called by vformat. oformat would have the guts of
vformat and just return the result list. vformat would then consist of the
call ot oformat and the join. See Below. The recursive call to _vformat would
also need some slight modification.
The work would not be difficult and I'm willing to do it, provided there is
sufficient interest.
def vformat(self, format_string, args, kwargs):
result = self.oformat(format_string, args, kwargs)
return ''.join(result)
def oformat(self, format_string, args, kwargs):
used_args = set()
result, _ = self._vformat(format_string, args, kwargs, used_args, 2)
self.check_unused_args(used_args, args, kwargs)
return result
----------
components: Library (Lib)
messages: 336945
nosy: Ross Biro
priority: normal
severity: normal
status: open
title: Modify Formatter Class to handle arbitrary objects
type: enhancement
versions: Python 2.7, Python 3.8
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue36159>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com