[Python-ideas] Non-boolean return from __contains__

Masklinn masklinn at masklinn.net
Tue Jul 27 21:00:19 CEST 2010


On 2010-07-27, at 20:04 , Guido van Rossum wrote:
> On Tue, Jul 27, 2010 at 5:25 PM, Robert Kern <robert.kern at gmail.com> wrote:
>> I've occasionally wished that we could repurpose backticks for expression
>> literals:
>> 
>>  expr = `x + y*z`
>>  assert isinstance(expr, ast.Expression)
> 
> Maybe you could just as well make it a plain string literal and call a
> function that parses it into a parse tree:
> 
> expr = parse("x + y*z")
> assert isinstance(expr, ast.Expression)
> 
> The advantage of this approach is that you can define a different
> language too…

The nice thing about having it be special-sauce syntax is that it can be parsed along with the rest of the script, failing early, and it can be stored in bytecode. Whereas the string itself will only be parsed when the function is actually executed.


More information about the Python-ideas mailing list