Skip to content

Commit f812037

Browse files
Copilotletmaik
andcommitted
Fix Cython type annotations for CI compatibility
- Remove `from __future__ import annotations` (not supported in Cython) - Move typing imports inside TYPE_CHECKING block - Quote all type annotations to avoid runtime errors - This fixes compilation issues while keeping type checker support Co-authored-by: letmaik <530988+letmaik@users.noreply.github.com>
1 parent fd893dc commit f812037

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

rawpy/_rawpy.pyx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
# cython: embedsignature=True
33
# cython: language_level=3
44

5-
from __future__ import print_function, annotations
6-
from typing import Optional, Union, Tuple, List, Any
5+
from __future__ import print_function
6+
7+
from typing import TYPE_CHECKING
8+
9+
if TYPE_CHECKING:
10+
from typing import Optional, Union, Tuple, List, Any
711

812
from cpython.ref cimport PyObject, Py_INCREF
913
from cpython.bytes cimport PyBytes_FromStringAndSize
@@ -382,7 +386,7 @@ cdef class RawPy:
382386
def __enter__(self) -> 'RawPy':
383387
return self
384388

385-
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
389+
def __exit__(self, exc_type: 'Any', exc_val: 'Any', exc_tb: 'Any') -> None:
386390
self.close()
387391

388392
def close(self) -> None:
@@ -423,7 +427,7 @@ cdef class RawPy:
423427
res = self.p.open_file(path.encode('UTF-8'))
424428
self.handle_error(res)
425429

426-
def open_buffer(self, fileobj: Any) -> None:
430+
def open_buffer(self, fileobj: 'Any') -> None:
427431
"""
428432
Opens the given RAW image file-like object. Should be followed by a call to :meth:`~rawpy.RawPy.unpack`.
429433

@@ -800,7 +804,7 @@ cdef class RawPy:
800804
return np.PyArray_SimpleNewFromData(1, shape, np.NPY_USHORT,
801805
&self.p.imgdata.rawdata.color.curve)
802806

803-
def dcraw_process(self, params: Optional['Params'] = None, **kw) -> None:
807+
def dcraw_process(self, params: 'Optional[Params]' = None, **kw) -> None:
804808
"""
805809
Postprocess the currently loaded RAW image.
806810

@@ -905,7 +909,7 @@ cdef class RawPy:
905909
thumb = self.dcraw_make_mem_thumb()
906910
return thumb
907911

908-
def postprocess(self, params: Optional['Params'] = None, **kw) -> np.ndarray:
912+
def postprocess(self, params: 'Optional[Params]' = None, **kw) -> 'np.ndarray':
909913
"""
910914
Postprocess the currently loaded RAW image and return the
911915
new resulting image as numpy array.
@@ -1097,33 +1101,33 @@ class Params(object):
10971101
A class that handles postprocessing parameters.
10981102
"""
10991103
def __init__(self,
1100-
demosaic_algorithm: Optional['DemosaicAlgorithm'] = None,
1104+
demosaic_algorithm: 'Optional[DemosaicAlgorithm]' = None,
11011105
half_size: bool = False,
11021106
four_color_rgb: bool = False,
11031107
dcb_iterations: int = 0,
11041108
dcb_enhance: bool = False,
11051109
fbdd_noise_reduction: 'FBDDNoiseReductionMode' = FBDDNoiseReductionMode.Off,
1106-
noise_thr: Optional[float] = None,
1110+
noise_thr: 'Optional[float]' = None,
11071111
median_filter_passes: int = 0,
11081112
use_camera_wb: bool = False,
11091113
use_auto_wb: bool = False,
1110-
user_wb: Optional[List[float]] = None,
1114+
user_wb: 'Optional[List[float]]' = None,
11111115
output_color: 'ColorSpace' = ColorSpace.sRGB,
11121116
output_bps: int = 8,
1113-
user_flip: Optional[int] = None,
1114-
user_black: Optional[int] = None,
1115-
user_sat: Optional[int] = None,
1117+
user_flip: 'Optional[int]' = None,
1118+
user_black: 'Optional[int]' = None,
1119+
user_sat: 'Optional[int]' = None,
11161120
no_auto_bright: bool = False,
1117-
auto_bright_thr: Optional[float] = None,
1121+
auto_bright_thr: 'Optional[float]' = None,
11181122
adjust_maximum_thr: float = 0.75,
11191123
bright: float = 1.0,
1120-
highlight_mode: Union['HighlightMode', int] = HighlightMode.Clip,
1121-
exp_shift: Optional[float] = None,
1124+
highlight_mode: 'Union[HighlightMode, int]' = HighlightMode.Clip,
1125+
exp_shift: 'Optional[float]' = None,
11221126
exp_preserve_highlights: float = 0.0,
11231127
no_auto_scale: bool = False,
1124-
gamma: Optional[Tuple[float, float]] = None,
1125-
chromatic_aberration: Optional[Tuple[float, float]] = None,
1126-
bad_pixels_path: Optional[str] = None) -> None:
1128+
gamma: 'Optional[Tuple[float, float]]' = None,
1129+
chromatic_aberration: 'Optional[Tuple[float, float]]' = None,
1130+
bad_pixels_path: 'Optional[str]' = None) -> None:
11271131
"""
11281132

11291133
If use_camera_wb and use_auto_wb are False and user_wb is None, then

0 commit comments

Comments
 (0)