mirror of
https://github.com/mii443/tokenizers.git
synced 2025-08-23 00:35:35 +00:00
Using serde (serde_pyo3) to get __str__ and __repr__ easily. (#1588)
* Using serde (serde_pyo3) to get __str__ and __repr__ easily. * Putting it within tokenizers, it needs to be too specific. * Clippy is our friend. * Ruff. * Update the tests. * Pretty sure this is wrong (#1589) * Adding support for ellipsis. * Fmt. * Ruff. * Fixing tokenizer. --------- Co-authored-by: Eric Buehler <65165915+EricLBuehler@users.noreply.github.com>
This commit is contained in:
@ -16,8 +16,8 @@ use tokenizers as tk;
|
||||
/// Trainer will return an instance of this class when instantiated.
|
||||
#[pyclass(module = "tokenizers.trainers", name = "Trainer", subclass)]
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct PyTrainer {
|
||||
#[serde(flatten)]
|
||||
pub trainer: Arc<RwLock<TrainerWrapper>>,
|
||||
}
|
||||
|
||||
@ -69,6 +69,16 @@ impl PyTrainer {
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
fn __repr__(&self) -> PyResult<String> {
|
||||
crate::utils::serde_pyo3::repr(self)
|
||||
.map_err(|e| exceptions::PyException::new_err(e.to_string()))
|
||||
}
|
||||
|
||||
fn __str__(&self) -> PyResult<String> {
|
||||
crate::utils::serde_pyo3::to_string(self)
|
||||
.map_err(|e| exceptions::PyException::new_err(e.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
impl Trainer for PyTrainer {
|
||||
|
Reference in New Issue
Block a user