[Python-ideas] Enabling access to the AST for Python code

Ethan Furman ethan at stoneleaf.us
Fri May 22 04:22:46 CEST 2015


redirecting py-dev thread here

On 05/21/2015 07:06 PM, Greg wrote:
> On 22/05/2015 1:33 p.m., Ethan Furman wrote:

>> Going back to the OP:
>>
>>>     select(c for c in Customer if sum(c.orders.price) > 1000)
>>>
>>> which compile into and run SQL like this:
>>>
>>>     SELECT "c"."id"
>>>     FROM "Customer" "c"
>>>     LEFT JOIN "Order" "order-1" ON "c"."id" = "order-1"."customer"
>>>     GROUP BY "c"."id"
>>>     HAVING coalesce(SUM("order-1"."total_price"), 0) > 1000
>>
>> That last code is /not/ Python.  ;)
>
> More importantly, it's not Python *semantics*. You can't view
> it as simply a translation of the Python expression into a
> different language.

Ah, I think I see -- that 'select' isn't really doing anything is it?  The 'if' clause is acting as the 'select' in the gen-exp.

But then `sum(c.orders.price)` isn't really Python semantics either, is it... although it could be if it was souped up -- `c.orders` would have to return a customer-based object that was smart enough 
to return a list of whatever attribute was asked for.  That'd be cool.

--
~Ethan~


More information about the Python-ideas mailing list