mirror of
https://github.com/mii443/tokenizers.git
synced 2025-08-23 00:35:35 +00:00
Python - Add Encoding repr + improve example
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
extern crate tokenizers as tk;
|
||||
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::PyObjectProtocol;
|
||||
|
||||
#[pyclass]
|
||||
#[pyclass(dict)]
|
||||
#[repr(transparent)]
|
||||
pub struct Encoding {
|
||||
encoding: tk::tokenizer::Encoding,
|
||||
@ -14,6 +15,16 @@ impl Encoding {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyproto]
|
||||
impl PyObjectProtocol for Encoding {
|
||||
fn __repr__(&self) -> PyResult<String> {
|
||||
Ok(format!(
|
||||
"Encoding {{ original: '{}', ... }}",
|
||||
self.encoding.get_original()
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl Encoding {
|
||||
#[getter]
|
||||
|
Reference in New Issue
Block a user