[Python-ideas] Draft PEP on string interpolation

Nikolaus Rath Nikolaus at rath.org
Wed Aug 26 18:05:37 CEST 2015


On Aug 26 2015, Nick Coghlan <ncoghlan-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> wrote:
> I'm also going to switch to using completely made up API names, since
> folks otherwise anchor on "but that's not the way that API currently
> works" without accounting for the fact that APIs can be updated to
> dispatch to different behaviours based on the types of their arguments
> :)

If you "update" subprocess.call (I assume this is one of the examples
you have in mind) to perform proper escaping and calling a shell when
receiving a X-string, the caller now needs to check if he's actually
using the right version of the module. 

Before:

subprocess.call(['rm', file])

after:

if subprocess.__version__ < something:
   subprocess.call(['rm', file])
else:
   subprocess.call(sh'rm {file}')

is that really an improvement?

In practice you'd probably declare the dependency in setup.py instead,
but this just makes it more likely to go out-of-sync, or to be
completely lost when code is being cargo-culted.


Or are you proposing that sh'rm {file}' wouldn't actually behave like a
str, so str(sh'rm {file}') would fail? I guess that would work, but it
seems that would have other implications - aren't we talking about
*string* interpolation here? If the result isn't even behaving like a
str, this seems like a misnomer.


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.«


More information about the Python-ideas mailing list