Skip to content

Commit

Permalink
Implement __getattr__ to PyLogEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
jopemachine committed Jan 3, 2024
1 parent b5df635 commit 18ac9b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion binding/python/examples/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async def __aexit__(self, exc_type, exc, tb):

@routes.get("/get/{id}")
async def get(request: web.Request) -> web.Response:
store = request.app["state"]["store"]
store: HashStore = request.app["state"]["store"]
id = request.match_info["id"]
return web.Response(text=store.get(id))

Expand Down
11 changes: 10 additions & 1 deletion binding/python/src/bindings/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ impl AbstractLogEntry for PyLogEntry {
}
}

#[pymethods]
impl PyLogEntry {
fn __getattr__(&self, py: Python, attr: &str) -> PyResult<PyObject> {
let log_entry: &PyAny = self.log_entry.as_ref(py);
let attr_value = log_entry.getattr(attr)?;
Ok(Py::from(attr_value))
}
}

#[derive(Clone)]
#[pyclass(name = "AbstractStateMachine")]
pub struct PyFSM {
Expand Down Expand Up @@ -114,7 +123,7 @@ impl fmt::Display for PyFSM {
}
}

#[pymethods]
#[pymethods]
impl PyFSM {
fn __getattr__(&self, py: Python, attr: &str) -> PyResult<PyObject> {
let store: &PyAny = self.store.as_ref(py);
Expand Down

0 comments on commit 18ac9b7

Please sign in to comment.