From d8a73c89a70bc50e140aed131a8986a6ce9c11a5 Mon Sep 17 00:00:00 2001 From: Anthony MOI Date: Tue, 18 Feb 2020 18:24:13 -0500 Subject: [PATCH] Python - Add Encoding length --- bindings/python/src/encoding.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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]