[Python-ideas] Non-boolean return from __contains__

Alex Gaynor alex.gaynor at gmail.com
Tue Jul 27 20:14:20 CEST 2010


On Tue, Jul 27, 2010 at 1:04 PM, Guido van Rossum <guido at python.org> 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...
>
> --
> --Guido van Rossum (python.org/~guido)
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>

As an interesting (but perhaps not relevant) data point, the
documentation is rather nebulous as to whether the bool cast exists
(it says things like "should return true if", but never explicitly
that it takes the boolean value of the return from __contains__),
further it doesn't seem to be tested at all (to the point where I only
noticed today that PyPy's behavior is different, since this apparently
breaks no tests).

Alex

-- 
"I disapprove of what you say, but I will defend to the death your
right to say it." -- Voltaire
"The people's good is the highest law." -- Cicero
"Code can always be simpler than you think, but never as simple as you
want" -- Me



More information about the Python-ideas mailing list