Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions python/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.whl

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
7 changes: 6 additions & 1 deletion python/python/async_tiff/_ifd.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions python/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -136,5 +136,10 @@ fn to_py_enum_variant<'py>(
value: u16,
) -> PyResult<Bound<'py, PyAny>> {
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)
}
}