chore: eliminate all usage of pyo3::prelude::*

This commit is contained in:
2026-07-14 20:50:07 -04:00
parent 6abe278aa3
commit 17fabbf178
15 changed files with 42 additions and 27 deletions

View File

@@ -4,8 +4,8 @@ use ijson::{IArray, INumber, IObject, IString, IValue};
#[cfg(feature = "pyo3")]
use pyo3::{
exceptions::{PyException, PyTypeError, PyValueError},
prelude::*,
types::{PyList, PyNone},
types::{PyAnyMethods as _, PyList, PyNone, PyTypeMethods as _},
Borrowed, Bound, FromPyObject, IntoPyObject, PyAny, PyErr, Python,
};
use snafu::{ResultExt, Snafu};

View File

@@ -7,8 +7,8 @@ use itertools::Itertools;
#[cfg(feature = "pyo3")]
use pyo3::{
exceptions::PyTypeError,
prelude::*,
types::{PyNone, PyTuple},
types::{PyAnyMethods as _, PyNone, PyTuple, PyTypeMethods as _},
Borrowed, Bound, FromPyObject, IntoPyObject, PyAny, PyErr, Python,
};
use snafu::{ResultExt, Snafu};

View File

@@ -5,7 +5,11 @@ use driver_kasa::connection::LB130USHandle;
use futures::stream::{FuturesUnordered, StreamExt};
use home_assistant::{home_assistant::HomeAssistant, object_id::ObjectId};
use protocol::light::{Kelvin, TurnToTemperature};
use pyo3::prelude::*;
use pyo3::{
pyfunction, pymodule,
types::{PyModule, PyModuleMethods as _},
wrap_pyfunction, Bound, PyAny, PyResult, Python,
};
use shadow_rs::shadow;
use tokio::time::{interval, MissedTickBehavior};
use tracing::{level_filters::LevelFilter, Level};

View File

@@ -1,6 +1,9 @@
use super::id::Id;
use once_cell::sync::OnceCell;
use pyo3::{prelude::*, types::PyType};
use pyo3::{
types::{PyAnyMethods, PyModule, PyType},
Bound, FromPyObject, IntoPyObject, Py, PyAny, PyErr, Python,
};
/// The context that triggered something.
#[derive(Debug, FromPyObject)]

View File

@@ -1,5 +1,5 @@
use chrono::{DateTime, Utc};
use pyo3::prelude::*;
use pyo3::FromPyObject;
use super::event_origin::EventOrigin;

View File

@@ -2,7 +2,8 @@ use std::str::FromStr;
use pyo3::{
exceptions::{PyException, PyTypeError, PyValueError},
prelude::*,
types::PyAnyMethods,
Borrowed, FromPyObject, PyAny, PyErr,
};
use snafu::{ResultExt, Snafu};

View File

@@ -1,7 +1,8 @@
use std::convert::Infallible;
use pyo3::prelude::*;
use pyo3::{
types::PyAnyMethods as _, Borrowed, Bound, FromPyObject, IntoPyObject, Py, PyAny, PyErr, Python,
};
use python_utils::{detach, validate_type_by_name, TypeByNameValidationError};
use snafu::{ResultExt, Snafu};

View File

@@ -1,4 +1,4 @@
use pyo3::prelude::*;
use pyo3::FromPyObject;
#[derive(Debug, FromPyObject)]
#[pyo3(from_item_all)]

View File

@@ -1,5 +1,5 @@
use attributes::LightAttributes;
use pyo3::prelude::*;
use pyo3::{FromPyObject, Py, PyAny, Python};
use snafu::{ResultExt, Snafu};
use state::LightState;

View File

@@ -7,7 +7,7 @@ use crate::{
state::{ErrorState, HomeAssistantState, UnexpectedState},
};
use protocol::light::{GetState, SetState};
use pyo3::prelude::*;
use pyo3::Python;
use python_utils::IsNone;
use snafu::{ResultExt, Snafu};

View File

@@ -1,6 +1,9 @@
use arbitrary_value::{arbitrary::Arbitrary, map::Map};
use once_cell::sync::OnceCell;
use pyo3::{prelude::*, types::PyTuple};
use pyo3::{
types::{PyAnyMethods as _, PyModule, PyTuple},
Borrowed, FromPyObject, IntoPyObject, Py, PyAny, PyErr, Python,
};
use python_utils::{detach, validate_type_by_name, TypeByNameValidationError};
#[derive(Debug)]
@@ -54,7 +57,7 @@ pub struct LogData<ExcInfo> {
}
impl HassLogger {
pub fn new(py: Python<'_>, name: &str) -> PyResult<Self> {
pub fn new(py: Python<'_>, name: &str) -> Result<Self, PyErr> {
static LOGGING_MODULE: OnceCell<Py<PyModule>> = OnceCell::new();
let logging_module = LOGGING_MODULE
@@ -71,7 +74,7 @@ impl HassLogger {
msg: &str,
args: Vec<Arbitrary>,
log_data: Option<LogData<ExcInfo>>,
) -> PyResult<()> {
) -> Result<(), PyErr> {
let mut all_args = vec![msg.into_pyobject(py)?.into_any()];
for arg in args {
let arg = arg.into_pyobject(py)?;
@@ -94,7 +97,7 @@ impl HassLogger {
msg: &str,
args: Vec<Arbitrary>,
log_data: Option<LogData<ExcInfo>>,
) -> PyResult<()> {
) -> Result<(), PyErr> {
let mut all_args = vec![msg.into_pyobject(py)?.into_any()];
for arg in args {
let arg = arg.into_pyobject(py)?;
@@ -117,7 +120,7 @@ impl HassLogger {
msg: &str,
args: Vec<Arbitrary>,
log_data: Option<LogData<ExcInfo>>,
) -> PyResult<()> {
) -> Result<(), PyErr> {
let mut all_args = vec![msg.into_pyobject(py)?.into_any()];
for arg in args {
let arg = arg.into_pyobject(py)?;
@@ -141,7 +144,7 @@ impl HassLogger {
msg: &str,
args: Vec<Arbitrary>,
log_data: Option<LogData<ExcInfo>>,
) -> PyResult<()> {
) -> Result<(), PyErr> {
let mut all_args = vec![msg.into_pyobject(py)?.into_any()];
for arg in args {
let arg = arg.into_pyobject(py)?;
@@ -164,7 +167,7 @@ impl HassLogger {
msg: &str,
args: Vec<Arbitrary>,
log_data: Option<LogData<ExcInfo>>,
) -> PyResult<()> {
) -> Result<(), PyErr> {
let mut all_args = vec![msg.into_pyobject(py)?.into_any()];
for arg in args {
let arg = arg.into_pyobject(py)?;

View File

@@ -1,7 +1,9 @@
use super::{event::context::context::Context, service::IntoServiceCall};
use pyo3::{
conversion::FromPyObjectOwned,
exceptions::{PyException, PyTypeError},
prelude::*,
types::PyAnyMethods as _,
Borrowed, FromPyObject, IntoPyObject, Py, PyAny, PyErr, Python,
};
use python_utils::{detach, validate_type_by_name, TypeByNameValidationError};
use snafu::{ResultExt, Snafu};
@@ -73,7 +75,7 @@ impl ServiceRegistry {
return_response,
);
let future = Python::attach::<_, PyResult<_>>(|py| {
let future = Python::attach::<_, Result<_, PyErr>>(|py| {
let service_registry = self.0.bind(py);
let awaitable = service_registry.call_method("async_call", args, None)?;
pyo3_async_runtimes::tokio::into_future(awaitable)

View File

@@ -2,7 +2,7 @@ use std::sync::Arc;
use super::entity_id::EntityId;
use super::state_object::StateObject;
use pyo3::prelude::*;
use pyo3::{conversion::FromPyObjectOwned, Borrowed, FromPyObject, Py, PyAny, PyErr, Python};
use python_utils::{detach, validate_type_by_name, TypeByNameValidationError};
use snafu::{ResultExt, Snafu};

View File

@@ -7,8 +7,8 @@ use chrono::{DateTime, Utc};
use emitter_and_signal::signal::Signal;
use once_cell::sync::OnceCell;
use pyo3::{
prelude::*,
types::{PyCFunction, PyDict, PyTuple},
types::{PyAnyMethods as _, PyCFunction, PyDict, PyModule, PyTuple},
Bound, FromPyObject, IntoPyObject as _, Py, PyAny, PyErr, Python,
};
use snafu::{ResultExt, Snafu};
use std::{future::Future, sync::Arc};
@@ -86,7 +86,7 @@ impl<
while let Some(publisher) = publisher_stream.wait().await {
let (new_state_sender, mut new_state_receiver) = mpsc::channel(8);
let untrack = Python::attach::<_, PyResult<_>>(|py| {
let untrack = Python::attach::<_, Result<_, PyErr>>(|py| {
static EVENT_MODULE: OnceCell<Py<PyModule>> = OnceCell::new();
let event_module = EVENT_MODULE

View File

@@ -1,6 +1,7 @@
use pyo3::{
exceptions::{PyException, PyTypeError},
prelude::*,
types::{PyAnyMethods as _, PyStringMethods, PyTypeMethods as _},
Borrowed, Bound, Py, PyAny, PyErr,
};
use snafu::{ResultExt, Snafu};