[TIP] Teaching pylint about keyword placeholders in string formatting

Ben Finney ben+python at benfinney.id.au
Wed Jul 15 17:45:53 PDT 2009


Marius Gedminas <marius at gedmin.as> writes:

> For some reason I mislike the use of vars()/locals()/globals() for use
> cases other than debugging, so I tend to write
> 
>           spangulate("%(warble)s: %(foo)s%(bar)s [%(baz)d]"
>                      % dict(warble=warble, foo=foo, bar=bar, baz=baz))

That has each name *three* times rather than once. Adhering to DRY is
the main reason I prefer using ‘vars()’ for populating keyword
placeholders, and the above perversely subverts DRY.

Of course, it's the fact that the names aren't repeated (as Python
identifiers) that causes pylint to complain at the moment, so I look
forward to the reported ticket being resolved satisfactorily.

> and therefore never have the problem with pylint. (Though I prefer
> pyflakes. Fewer erroneous warnings, or at least I got that
> impression.)

I craft a configuration file for pylint (there's unfortunately no good
documentation on this file, but ‘pylint --generate-rcfile > foo.conf’
will give you an editable configuration file), so that the reports
better match project conventions.

-- 
 \       “Working out the social politics of who you can trust and why |
  `\      is, quite literally, what a very large part of our brain has |
_o__)                                   evolved to do.” —Douglas Adams |
Ben Finney
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.idyll.org/pipermail/testing-in-python/attachments/20090716/4939811e/attachment.pgp 


More information about the testing-in-python mailing list