How Pony (ORM) does its tricks?
Pony ORM does the nice trick of converting a generator expression into SQL. Example: >>> select(p for p in Person if p.name.startswith('Paul')) .order_by(Person.name)[:2] SELECT "p"."id", "p"."name", "p"."age" FROM "Person" "p" WHERE "p"."name" LIKE "Paul%" ORDER BY "p"."name" LIMIT 2 [Person[3], Person[1]] >>> I know Python has wonderful introspection and metaprogramming builtin, but how this library is able to translate the generator expression without preprocessing? It looks like magic. [update] Blender wrote: Here is the file that you're after. It seems to reconstruct the generator using