Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions python/egglog/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,9 @@ def to_string(self) -> String: ...
@method(egg_fn="py-to-bool")
def to_bool(self) -> Bool: ...

@method(egg_fn="py-to-int")
def to_int(self) -> i64: ...

@method(egg_fn="py-dict-update")
def dict_update(self, *keys_and_values: object) -> PyObject: ...

Expand Down
3 changes: 3 additions & 0 deletions python/tests/test_high_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ def test_from_string(self):
def test_to_string(self):
EGraph().check(PyObject("foo").to_string() == String("foo"))

def test_to_int(self):
EGraph().check(PyObject(42).to_int() == i64(42))

def test_dict_update(self):
original_d = {"foo": "bar"}
res = EGraph().extract(PyObject(original_d).dict_update("foo", "baz")).value
Expand Down
9 changes: 9 additions & 0 deletions src/py_object_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ impl BaseSort for PyObjectSort {
}
}
);
// (py-to-int <obj>)
add_primitive!(
eg,
"py-to-int" = |x: PyPickledValue| -?> i64 {
{
attach("py-to-int", move |py| load(py, &x)?.extract())
}
}
);
// (py-from-string <str>)
add_primitive!(
eg,
Expand Down