|
|
|
|
|
by shakna
2996 days ago
|
|
I really don't like the stringly API. It'll defeat anything my editor can predict, making typos easier. It also makes it harder to reason about types, as I have to trust the library to make the right assumption. [0] Instead of: dq.match(data, "`friends.age` <= 26")
Why not: import operator # from the standard library
dq.match(data, "friends.age", operator.le, 26)
It'll simplify your parsing, works with my editor, and makes it easier to reason about types. You'll still need to parse, as you're basically handling a variadic function, but the user can hand you an AST.--- [0] For example, what type would occur if: dq.match(data, "`friends.age` <= 26.")
Does 26 become a float? Or an integer? Or raise a ParseError?I have to consider that with a string, less so with Python's own objects. |
|
dq.match(data, Field("friends.age") <= 26)
or in the appengine style if data is some class (say Friend):
dq.match(data, Friend__age <= 26)