refactor(py): update the type stubs (and expose DType)

This commit is contained in:
Anand Balakrishnan 2023-05-04 13:33:56 -07:00
parent 9b07df440b
commit 31c65a4734
No known key found for this signature in database
10 changed files with 102 additions and 56 deletions

View file

@ -27,11 +27,22 @@ impl From<PyArgusError> for PyErr {
}
}
#[pyclass]
#[derive(Copy, Clone, Debug)]
pub enum DType {
Bool,
Int,
UnsignedInt,
Float,
}
#[pymodule]
#[pyo3(name = "_argus")]
fn pyargus(py: Python, m: &PyModule) -> PyResult<()> {
pyo3_log::init();
m.add_class::<DType>()?;
expr::init(py, m)?;
signals::init(py, m)?;
semantics::init(py, m)?;

View file

@ -7,8 +7,8 @@ use pyo3::prelude::*;
use pyo3::types::{PyDict, PyString};
use crate::expr::PyBoolExpr;
use crate::signals::{BoolSignal, FloatSignal, IntSignal, Kind, PySignal, UnsignedIntSignal};
use crate::PyArgusError;
use crate::signals::{BoolSignal, FloatSignal, IntSignal, PySignal, UnsignedIntSignal};
use crate::{DType, PyArgusError};
#[derive(Debug, Clone, derive_more::From, derive_more::TryInto)]
#[try_into(owned, ref, ref_mut)]
@ -42,16 +42,16 @@ impl PyTrace {
})?;
let kind = val.borrow().kind;
let signal: SignalKind = match kind {
Kind::Bool => val.downcast::<PyCell<BoolSignal>>().unwrap().borrow().0.clone().into(),
Kind::Int => val.downcast::<PyCell<IntSignal>>().unwrap().borrow().0.clone().into(),
Kind::UnsignedInt => val
DType::Bool => val.downcast::<PyCell<BoolSignal>>().unwrap().borrow().0.clone().into(),
DType::Int => val.downcast::<PyCell<IntSignal>>().unwrap().borrow().0.clone().into(),
DType::UnsignedInt => val
.downcast::<PyCell<UnsignedIntSignal>>()
.unwrap()
.borrow()
.0
.clone()
.into(),
Kind::Float => val.downcast::<PyCell<FloatSignal>>().unwrap().borrow().0.clone().into(),
DType::Float => val.downcast::<PyCell<FloatSignal>>().unwrap().borrow().0.clone().into(),
};
signals.insert(key.to_string(), signal);

View file

@ -3,20 +3,12 @@ use std::time::Duration;
use argus_core::signals::{InterpolationMethod, Signal};
use pyo3::prelude::*;
use crate::PyArgusError;
#[derive(Copy, Clone, Debug)]
pub enum Kind {
Bool,
Int,
UnsignedInt,
Float,
}
use crate::{DType, PyArgusError};
#[pyclass(name = "Signal", subclass, module = "argus")]
#[derive(Debug, Clone)]
pub struct PySignal {
pub kind: Kind,
pub kind: DType,
pub interpolation: InterpolationMethod,
}
@ -32,7 +24,7 @@ macro_rules! impl_signals {
pub fn super_type() -> PySignal {
PySignal {
interpolation: InterpolationMethod::Linear,
kind: Kind::$ty_name,
kind: DType::$ty_name,
}
}
}