Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does this App Engine Ndb syntax work?

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 the User class, which inherits from ndb.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?

like image 251
Chris Avatar asked Apr 28 '26 08:04

Chris


1 Answers

You're missing python magic methods.

__eq__(self, other)

Defines behavior for the equality operator, ==.

Good guide about this could be found here.

like image 109
Dmytro Sadovnychyi Avatar answered Apr 30 '26 22:04

Dmytro Sadovnychyi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!