[Python-ideas] template strings

Steven D'Aprano steve at pearwood.info
Tue Aug 18 02:34:11 CEST 2015


On Mon, Aug 17, 2015 at 08:24:43PM -0400, Yury Selivanov wrote:
> On 2015-08-17 7:24 PM, MRAB wrote:

> >What happens if you accidentally omit a comma?
> >
> >    print(count ' items found')
> >
> >Currently it's a syntax error, but, with this proposal, it becomes a
> >runtime error:
> >
> >    AttributeError: 'int' object has no attribute '__format_str__'
> >
> 
> Exactly.  We can also (probably) use symtable to lookup 'count'
> name and throw a SyntaxError if it's not defined.

Why would you do that? The syntax is fine. It's a name lookup error, not 
a syntax error, so you should raise NameError, like everything else is 
Python does when a name is not defined.

SyntaxError should be used for syntax errors. Under your proposal, 

    count ' items found'

will be valid syntax.



-- 
Steve


More information about the Python-ideas mailing list