[Python-ideas] Fix the DRY problem (was Re: PEP 501 - i18n with marked strings)

Barry Warsaw barry at python.org
Tue Aug 11 17:20:43 CEST 2015


On Aug 11, 2015, at 12:50 PM, Petr Viktorin wrote:

>Not having to repeat the variable name three times.

To me, this is really the crux of both the f-string and i-string proposals.
It's also a more general issue it me because it's almost exactly the raison
d'être for flufl.i18n.

The complicated examples of f-strings I've seen really give me the shudders.
Maybe in practice it won't be so bad, but it's definitely true that if it can
be done, someone will do it.  So I expect to see "abuses" of them in the wild.

But the DRY argument is much more compelling to me, and currently I think the
best way to reduce repetition in function arguments is through sys._getframe()
and other such nasty tricks.  I'd really much prefer to see this small
annoyance fixed in a targeted way than add a hugely complicated new feature
that reduces readability (IMHO).

Which is why I like the scope() and similar ideas.  Something like a built-in
that provides you with a ChainMap of the current namespaces in effect.  The
tricky bit is that you still need something like _getframe()'s depth argument,
or perhaps the object returned by scope() -or whatever it's called- would have
links back to the namespaces of earlier call frames.  I also don't know
whether all of this makes sense for all the alternative implementations, but
there's certainly a *logical* call stack for any particular point in a Python
program.

What's the simplest thing we can do to make this pain go away?

A few extraneous locals really aren't that bad.  They'll be rarely needed, and
besides I already use such things when the alternative is a hideously long
line of code.  In any case, they're a small price to pay for keeping things
simple.

Cheers,
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150811/f1f019d4/attachment.sig>


More information about the Python-ideas mailing list