[pacman-dev] [PATCH v2 7/8] Add parens around tuples in Python list comprehensions.

Martin Panter vadmium+patch at gmail.com
Sat Oct 12 18:26:24 EDT 2013


On 13 October 2013 07:24, William Giokas <1007380 at gmail.com> wrote:
> I believe the actual correct way to do string formatting here is to use
> something like 'str'.format(something) instead of 'str' % something.
>
> This is available in python 2.6, 2.7, and 3.3 at least.
>
> http://www.python.org/dev/peps/pep-3101/ (note the 'both systems can
> co-exist until it comes time to deprecate the older system.' at the end)

>> diff --git a/test/pacman/tests/depconflict100.py b/test/pacman/tests/depconflict100.py
>> index 948017d..72cbec6 100644
>> --- a/test/pacman/tests/depconflict100.py
>> +++ b/test/pacman/tests/depconflict100.py
>> @@ -7,7 +7,7 @@
>>  sp2 = pmpkg("pkg2", "1.0-2")
>>  self.addpkg2db("sync", sp2)
>>
>> -self.args = "-S %s" % " ".join([p.name for p in sp1, sp2])
>> +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)])
> So, for example:
> self.args = "-S {}".format(" ".join[p.name for p in (sp1, sp2)])

Jeremy’s patch looks fine for the purpose of Python 3 porting.

But if you want to clean these lines up further, can I suggest also
dropping the list comprehension for a generator expression? Note no
square brackets:

" ".join(p.name for p in (sp1, sp2))

-Martin


More information about the pacman-dev mailing list