diff --git a/python/.gitignore b/python/.gitignore index 68bc17f..d4add73 100644 --- a/python/.gitignore +++ b/python/.gitignore @@ -1,3 +1,5 @@ +*.whl + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/python/python/async_tiff/_ifd.pyi b/python/python/async_tiff/_ifd.pyi index 6466dfb..5bf173c 100644 --- a/python/python/async_tiff/_ifd.pyi +++ b/python/python/async_tiff/_ifd.pyi @@ -24,7 +24,12 @@ class ImageFileDirectory: @property def bits_per_sample(self) -> list[int]: ... @property - def compression(self) -> CompressionMethod: ... + def compression(self) -> CompressionMethod | int: + """Access the compression tag. + + An `int` will be returned if the compression is not one of the values in + `CompressionMethod`. + """ @property def photometric_interpretation(self) -> PhotometricInterpretation: ... @property diff --git a/python/src/enums.rs b/python/src/enums.rs index c80fbb4..14656bd 100644 --- a/python/src/enums.rs +++ b/python/src/enums.rs @@ -2,9 +2,9 @@ use async_tiff::tiff::tags::{ CompressionMethod, PhotometricInterpretation, PlanarConfiguration, Predictor, ResolutionUnit, SampleFormat, }; -use pyo3::intern; use pyo3::prelude::*; use pyo3::types::{PyString, PyTuple}; +use pyo3::{intern, IntoPyObjectExt}; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub(crate) struct PyCompressionMethod(CompressionMethod); @@ -136,5 +136,10 @@ fn to_py_enum_variant<'py>( value: u16, ) -> PyResult> { let enums_mod = py.import(intern!(py, "async_tiff.enums"))?; - enums_mod.call_method1(enum_name, PyTuple::new(py, vec![value])?) + if let Ok(enum_variant) = enums_mod.call_method1(enum_name, PyTuple::new(py, vec![value])?) { + Ok(enum_variant) + } else { + // If the value is not included in the enum, return the integer itself + value.into_bound_py_any(py) + } }