1818
1919import abc
2020import functools
21- from typing import Sequence
21+ from types import ModuleType
22+ from typing import Any , Sequence
2223
2324
2425class Filter :
@@ -57,7 +58,13 @@ class Kernel(BuiltinFilter):
5758
5859 name = "Kernel"
5960
60- def __init__ (self , size , kernel , scale = None , offset = 0 ):
61+ def __init__ (
62+ self ,
63+ size : tuple [int , int ],
64+ kernel : Sequence [float ],
65+ scale : float | None = None ,
66+ offset : float = 0 ,
67+ ) -> None :
6168 if scale is None :
6269 # default scale is sum of kernel
6370 scale = functools .reduce (lambda a , b : a + b , kernel )
@@ -194,10 +201,8 @@ class BoxBlur(MultibandFilter):
194201
195202 name = "BoxBlur"
196203
197- def __init__ (self , radius ):
198- xy = radius
199- if not isinstance (xy , (tuple , list )):
200- xy = (xy , xy )
204+ def __init__ (self , radius : float | Sequence [float ]) -> None :
205+ xy = radius if isinstance (radius , (tuple , list )) else (radius , radius )
201206 if xy [0 ] < 0 or xy [1 ] < 0 :
202207 msg = "radius must be >= 0"
203208 raise ValueError (msg )
@@ -381,7 +386,9 @@ class Color3DLUT(MultibandFilter):
381386
382387 name = "Color 3D LUT"
383388
384- def __init__ (self , size , table , channels = 3 , target_mode = None , ** kwargs ):
389+ def __init__ (
390+ self , size , table , channels : int = 3 , target_mode : str | None = None , ** kwargs
391+ ):
385392 if channels not in (3 , 4 ):
386393 msg = "Only 3 or 4 output channels are supported"
387394 raise ValueError (msg )
@@ -395,7 +402,7 @@ def __init__(self, size, table, channels=3, target_mode=None, **kwargs):
395402 items = size [0 ] * size [1 ] * size [2 ]
396403 wrong_size = False
397404
398- numpy = None
405+ numpy : ModuleType | None = None
399406 if hasattr (table , "shape" ):
400407 try :
401408 import numpy
@@ -442,7 +449,7 @@ def __init__(self, size, table, channels=3, target_mode=None, **kwargs):
442449 self .table = table
443450
444451 @staticmethod
445- def _check_size (size ) :
452+ def _check_size (size : Any ) -> list [ int ] :
446453 try :
447454 _ , _ , _ = size
448455 except ValueError as e :
0 commit comments