Guido van Rossum's Ndb
library for Google App Engine has a syntax for queries that I find curious. Suppose you wanted to find all happy users, you would write this query:
User.query(User.happy == True)
I read that as:
- A function call of the
query
method of theUser
class, which inherits fromndb.Model
. Fine so far. - The one argument of the function call is an expression doing a boolean comparison between a class property,
User.happy
, and a value,True
.
I would expect the expression to evaluate to False
(much as dict.keys == True
would), so the above should be equivalent to:
User.query(False)
How does Ndb do anything intelligent with that? What python magic am I missing?