chore: take Python<'_> as a parameter instead of &Python

This commit is contained in:
2025-03-22 16:49:45 -04:00
parent 7b2ebc5fe9
commit 70dda580ee
3 changed files with 16 additions and 16 deletions

View File

@@ -19,25 +19,25 @@ impl<'source> FromPyObject<'source> for HomeAssistant {
impl HomeAssistant { impl HomeAssistant {
/// Return the representation /// Return the representation
pub fn repr(&self, py: &Python) -> Result<String, PyErr> { pub fn repr(&self, py: Python<'_>) -> Result<String, PyErr> {
let bound = self.0.bind(*py); let bound = self.0.bind(py);
let repr = bound.repr()?; let repr = bound.repr()?;
repr.extract() repr.extract()
} }
/// Return if Home Assistant is running. /// Return if Home Assistant is running.
pub fn is_running(&self, py: &Python) -> Result<bool, PyErr> { pub fn is_running(&self, py: Python<'_>) -> Result<bool, PyErr> {
let is_running = self.0.getattr(*py, "is_running")?; let is_running = self.0.getattr(py, "is_running")?;
is_running.extract(*py) is_running.extract(py)
} }
/// Return if Home Assistant is stopping. /// Return if Home Assistant is stopping.
pub fn is_stopping(&self, py: &Python) -> Result<bool, PyErr> { pub fn is_stopping(&self, py: Python<'_>) -> Result<bool, PyErr> {
let is_stopping = self.0.getattr(*py, "is_stopping")?; let is_stopping = self.0.getattr(py, "is_stopping")?;
is_stopping.extract(*py) is_stopping.extract(py)
} }
pub fn states(&self, py: &Python) -> Result<StateMachine, PyErr> { pub fn states(&self, py: Python<'_>) -> Result<StateMachine, PyErr> {
let states = self.0.getattr(*py, "states")?; let states = self.0.getattr(py, "states")?;
states.extract(*py) states.extract(py)
} }
} }

View File

@@ -23,11 +23,11 @@ impl<'py> FromPyObject<'py> for StateMachine {
impl StateMachine { impl StateMachine {
pub fn get<Attributes: for<'py> FromPyObject<'py>, ContextEvent: for<'py> FromPyObject<'py>>( pub fn get<Attributes: for<'py> FromPyObject<'py>, ContextEvent: for<'py> FromPyObject<'py>>(
&self, &self,
py: &Python, py: Python<'_>,
entity_id: EntityId, entity_id: EntityId,
) -> Result<Option<State<Attributes, ContextEvent>>, PyErr> { ) -> PyResult<Option<State<Attributes, ContextEvent>>> {
let args = (entity_id.to_string(),); let args = (entity_id.to_string(),);
let state = self.0.call_method1(*py, "get", args)?; let state = self.0.call_method1(py, "get", args)?;
state.extract(*py) state.extract(py)
} }
} }

View File

@@ -47,7 +47,7 @@ async fn real_main(home_assistant: HomeAssistant) -> ! {
} }
#[pyfunction] #[pyfunction]
fn main<'p>(py: Python<'p>, home_assistant: HomeAssistant) -> PyResult<Bound<'p, PyAny>> { fn main<'py>(py: Python<'py>, home_assistant: HomeAssistant) -> PyResult<Bound<'py, PyAny>> {
pyo3_async_runtimes::tokio::future_into_py::<_, ()>(py, async { pyo3_async_runtimes::tokio::future_into_py::<_, ()>(py, async {
real_main(home_assistant).await; real_main(home_assistant).await;
}) })