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:
@ -44,8 +44,8 @@ impl PyNormalizedStringMut<'_> {
|
||||
/// Normalizer will return an instance of this class when instantiated.
|
||||
#[pyclass(dict, module = "tokenizers.normalizers", name = "Normalizer", subclass)]
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct PyNormalizer {
|
||||
#[serde(flatten)]
|
||||
pub(crate) normalizer: PyNormalizerTypeWrapper,
|
||||
}
|
||||
|
||||
@ -169,6 +169,16 @@ impl PyNormalizer {
|
||||
ToPyResult(self.normalizer.normalize(&mut normalized)).into_py()?;
|
||||
Ok(normalized.get().to_owned())
|
||||
}
|
||||
|
||||
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()))
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! getter {
|
||||
|
Reference in New Issue
Block a user