You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference/python-integration.md
+5-10Lines changed: 5 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -379,13 +379,13 @@ instead of the normal mechanism which relies on `__getattr__`, you can call `egg
379
379
with the name of a method. This is only needed for third party code that inspects the type object itself to see if a
380
380
method is defined instead of just attempting to call it.
381
381
382
-
### Reflected methods
382
+
### Binary Method Conversions
383
383
384
-
Note that reflected methods (i.e. `__radd__`) are handled as a special case. If defined, they won't create their own egglog functions.
384
+
For [rich comparison methods](https://docs.python.org/3/reference/datamodel.html#object.__lt__) (like `__lt__`, `__le__`, `__eq__`, etc.) and [binary numeric methods](https://docs.python.org/3/reference/datamodel.html#object.__add__) (like `__add__`, `__sub__`, etc.), some more advanced conversion logic is needed to ensure they are converted properly. We add the `__r<name>__` methods for all expressions so that we can handle either position they are placed in.
385
385
386
-
Instead, whenever a reflected method is called, we will try to find the corresponding non-reflected method and call that instead.
387
-
388
-
Also, if a normal method fails because the arguments cannot be converted to the right types, the reflected version of the second arg will be tried.
386
+
If we have two values `lhs` and `rhs`, we will try to find the minimum cost conversion for both of them, and then call the method on the converted values.
387
+
If both are expression instances, we will convert at most one of them. However, if one is an expression and the other
388
+
is a different Python value (like an `int`), we will consider all possible conversions of both arguments to find the minimum.
For methods which allow returning `NotImplemented`, i.e. the comparison + binary math methods, we will also try upcasting both
427
-
types to the type which is lowest cost to convert both to.
428
-
429
-
For example, if you have `Float` and `Int` wrapper types and you have write the expr `-1.0 + Int.var("x")` you might want the result to be `Float(-1.0) + Float.from_int(Int.var("x"))`:
430
-
431
426
### Mutating arguments
432
427
433
428
In order to support Python functions and methods which mutate their arguments, you can pass in the `mutate_first_arg` keyword argument to the `@function` decorator and the `mutates_self` argument to the `@method` decorator. This will cause the first argument to be mutated in place, instead of being copied.
0 commit comments