[formatter] do NOT apply :J to strings (#2833)
This commit is contained in:
@@ -296,12 +296,14 @@ def _parse_maxlen(format_spec, default):
|
|||||||
|
|
||||||
def _parse_join(format_spec, default):
|
def _parse_join(format_spec, default):
|
||||||
separator, _, format_spec = format_spec.partition(_SEPARATOR)
|
separator, _, format_spec = format_spec.partition(_SEPARATOR)
|
||||||
separator = separator[1:]
|
join = separator[1:].join
|
||||||
fmt = _build_format_func(format_spec, default)
|
fmt = _build_format_func(format_spec, default)
|
||||||
|
|
||||||
def join(obj):
|
def apply_join(obj):
|
||||||
return fmt(separator.join(obj))
|
if isinstance(obj, str):
|
||||||
return join
|
return fmt(obj)
|
||||||
|
return fmt(join(obj))
|
||||||
|
return apply_join
|
||||||
|
|
||||||
|
|
||||||
def _parse_replace(format_spec, default):
|
def _parse_replace(format_spec, default):
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ class TestFormatter(unittest.TestCase):
|
|||||||
self._run_test("{l:J - />20}", " a - b - c")
|
self._run_test("{l:J - />20}", " a - b - c")
|
||||||
|
|
||||||
self._run_test("{a:J/}" , self.kwdict["a"])
|
self._run_test("{a:J/}" , self.kwdict["a"])
|
||||||
self._run_test("{a:J, /}" , ", ".join(self.kwdict["a"]))
|
self._run_test("{a:J, /}" , self.kwdict["a"])
|
||||||
|
|
||||||
def test_replace(self):
|
def test_replace(self):
|
||||||
self._run_test("{a:Rh/C/}" , "CElLo wOrLd")
|
self._run_test("{a:Rh/C/}" , "CElLo wOrLd")
|
||||||
|
|||||||
Reference in New Issue
Block a user