Why is this python expression parameter is not expanded at call time?
--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Magical Minnie Puzzles
--
Chapters
00:00 Why Is This Python Expression Parameter Is Not Expanded At Call Time?
00:27 Accepted Answer Score 2
01:36 Thank you
--
Full question
https://stackoverflow.com/questions/4720...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #function #googleappengine #arguments #parameterpassing
#avk47
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Magical Minnie Puzzles
--
Chapters
00:00 Why Is This Python Expression Parameter Is Not Expanded At Call Time?
00:27 Accepted Answer Score 2
01:36 Thank you
--
Full question
https://stackoverflow.com/questions/4720...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #function #googleappengine #arguments #parameterpassing
#avk47
ACCEPTED ANSWER
Score 2
Ignacio is correct, the NDB code is defining custom magic methods on its Property class for comparison checking. These functions (__eq__, __ne__, __lt__, etc.) are all calling this custom _comparison function under the hood.
def _comparison(self, op, value):
"""Internal helper for comparison operators.
Args:
op: The operator ('=', '<' etc.).
Returns:
A FilterNode instance representing the requested comparison.
"""
# NOTE: This is also used by query.gql().
if not self._indexed:
raise datastore_errors.BadFilterError(
'Cannot query for unindexed property %s' % self._name)
from .query import FilterNode # Import late to avoid circular imports.
if value is not None:
value = self._do_validate(value)
value = self._call_to_base_type(value)
value = self._datastore_type(value)
return FilterNode(self._name, op, value)
As you can see, the code doesn't return a boolean result, it returns an instance of FilterNode which itself evaluates to a truthy/falsey value appropriately for the comparison.
How come the
Account.userid >= 40expression is not expanded at call time to true or false before passed as an argument?
It technically is getting expanded/evaluated before the query() function is called, it just isn't evaluating to a boolean value.