Search code examples
pythonparameter-passinggoogle-cloud-datastoreapp-engine-ndb

Python method parameter evaluated after method invocation


In the App Engine NDB documentation, there is the following:

FlexEmployee.query(FlexEmployee.location == 'SF')

How is it that "FlexEmployee.location == 'SF'" is not first evaluated and the boolean result passed into query()?


Solution

  • The trick is that the base ndb.Property class overrides the __eq__ method, so that it doesn't return a boolean but instead a FilterNode class that is passed into the actual query.

    So, it is evaluated before query is called, but the result of that evaluation is not a boolean.