[Python-ideas] Non-boolean return from __contains__

Antoine Pitrou solipsis at pitrou.net
Tue Jul 27 21:06:42 CEST 2010


On Tue, 27 Jul 2010 11:38:15 -0700
Raymond Hettinger
<raymond.hettinger at gmail.com> wrote:
> 
> On Jul 27, 2010, at 11:04 AM, Guido van Rossum wrote:
> 
> > On Tue, Jul 27, 2010 at 5:25 PM, Robert Kern <robert.kern-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> 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...
> 
> Starting with string literals and a parse function seems like
> a great design decision.   It already works and doesn't require
> new syntax.

Yes, you only have to write a dedicated full-fledged parser, your code
isn't highlighted properly in text editors, and you can't easily access
Python objects declared in the enclosing scope.

I guess it explains that none of the common ORMs seem to have adopted
such a “great design decision” :-)

Regards

Antoine.





More information about the Python-ideas mailing list