[Python-ideas] Briefer string format

Steven D'Aprano steve at pearwood.info
Mon Aug 3 16:08:52 CEST 2015


On Sun, Aug 02, 2015 at 10:43:03PM -0400, Eric V. Smith wrote:
> On 8/2/2015 7:46 PM, Mike Miller wrote:
> > Hi,
> > 
> > I don't understand how we got to arbitrary expressions.
> 
> I think here:
> https://mail.python.org/pipermail/python-ideas/2015-July/034701.html
> 
> > There was probably an edge case or two, but I wasn't expecting
> > str(eval(s)) to be the answer, and one I'm not sure I'd want.
> 
> As I pointed out earlier, it's not exactly str(eval(s)). Also, what's
> your concern with the suggested approach? There are no security concerns
> as there would be with eval-ing arbitrary strings.

Language features should be no more powerful than they need to be. It 
isn't just *security* that we should be concerned about, its also about 
readability, learnability, the likelihood of abuse by writing 
unmaintainable Perlish one-liners, and the general increase in 
complexity.

Or to put it another way... YAGNI.

We started of with a fairly simple and straightforward feature request: 
to make it easy to substitute named variables in format strings. We 
ought to be somewhat cautious about accepting even that limited version. 
After all, hundreds of languages don't have such a feature, and Python 
worked perfectly well without it for over 20 years. This doesn't add 
anything to the language that cannot already be done with % and 
str.format().

But suddenly we've gone from a feature request that has been routinely 
denied many times in the past (having variables be automatically 
substituted into strings), to full-blown evaluation of arbitrarily 
complex expressions being discussed as if it were a done-deal.

I've heard of the trick of asking for a pony if you actually want a 
puppy, but this is the first time I've seen somebody ask for a puppy and 
be given a thoroughbred.

Anyway, there's no harm done, since this is going through the PEP 
process. It just strikes me as so unlike the usual conservatism, 
particularly when it comes to syntax changes, that it surprised me. 
Perhaps somebody slipped something in the water? :-)



-- 
Steve


More information about the Python-ideas mailing list