diff --git a/src/utils/str.py b/src/utils/str.py index d9ca25f66..5f822e56f 100644 --- a/src/utils/str.py +++ b/src/utils/str.py @@ -478,15 +478,14 @@ def format(s, *args, **kwargs): return has(args.pop()) elif char == 'L': t = args.pop() - if isinstance(t, list) or (sys.version_info[0] >= 3 and - (isinstance(t, map) or isinstance(t, filter))): - return commaAndify(t) - elif isinstance(t, tuple) and len(t) == 2: + if isinstance(t, tuple) and len(t) == 2: if not isinstance(t[0], list): raise ValueError('Invalid list for %%L in format: %s' % t) if not isinstance(t[1], basestring): raise ValueError('Invalid string for %%L in format: %s' % t) return commaAndify(t[0], And=t[1]) + elif hasattr(t, '__iter__'): + return commaAndify(t) else: raise ValueError('Invalid value for %%L in format: %s' % t) elif char == 'p': diff --git a/test/test_utils.py b/test/test_utils.py index debad420f..ab41ea404 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -539,6 +539,18 @@ class FormatTestCase(SupyTestCase): 'I have 3 kinds of fruit: ' 'apples, oranges, and watermelon.') + def testPercentL(self): + self.assertIn(format('%L', {'apples', 'oranges', 'watermelon'}), { + 'apples, oranges, and watermelon', + 'oranges, apples, and watermelon', + 'apples, watermelon, and oranges', + 'oranges, watermelon, and apples', + 'watermelon, apples, and oranges', + 'watermelon, oranges, and apples'}) + + self.assertEqual(format('%L', + (['apples', 'oranges', 'watermelon'], 'or')), + 'apples, oranges, or watermelon') class RingBufferTestCase(SupyTestCase): def testInit(self): self.assertRaises(ValueError, RingBuffer, -1)