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

Nikolaus Rath Nikolaus at rath.org
Wed Aug 12 04:33:18 CEST 2015


On Aug 11 2015, Barry Warsaw <barry-+ZN9ApsXKcEdnm+yROfE0A at public.gmane.org> wrote:
> 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.
[...]
> 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.

You mean instead of allowing expressions inside strings, you want to
make it easier for functions to mess with their callers scope?

def test():
    x = 3
    print(x) --> 3
    increas_my_x()
    print(x) --> 4

def increase_my_x():
    scope(depth=-1)['x'] += 1


Somehow I think the risk of abuse here is much higher than with
expression strings. At least their effects are local.


Best,
-Nikolaus
-- 
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             »Time flies like an arrow, fruit flies like a Banana.«
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 997 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150811/688108d9/attachment-0001.sig>


More information about the Python-ideas mailing list