diff --git a/bindings/python/src/encoding.rs b/bindings/python/src/encoding.rs index 3056c371..7da839e7 100644 --- a/bindings/python/src/encoding.rs +++ b/bindings/python/src/encoding.rs @@ -4,7 +4,7 @@ use crate::error::PyError; use pyo3::exceptions; use pyo3::prelude::*; use pyo3::types::*; -use pyo3::{PyMappingProtocol, PyObjectProtocol}; +use pyo3::{PyMappingProtocol, PyObjectProtocol, PySequenceProtocol}; use tk::tokenizer::PaddingDirection; fn get_range(item: PyObject, max_len: usize) -> PyResult> { @@ -133,6 +133,13 @@ impl PyObjectProtocol for Encoding { } } +#[pyproto] +impl PySequenceProtocol for Encoding { + fn __len__(self) -> PyResult { + Ok(self.encoding.get_ids().len()) + } +} + #[pymethods] impl Encoding { #[getter]