flrs / blend_modes

Python package that implements image blend modes
MIT License
140 stars 29 forks source link

Add type hints for clarity #15

Open flrs opened 5 years ago

flrs commented 5 years ago

We should add type hints to improve clarity regarding inputs and outputs.

amirothman commented 4 years ago

do you have any suggestions for which portion of the code would be most helpful if we were to add type hinting?

flrs commented 4 years ago

Hi @amirothman,

I think type hinting could be useful for all blending functions. For example:

https://github.com/flrs/blend_modes/blob/4eca9470a210049db32b3fd2e95cc17d5b58e7bc/blend_modes/blending_functions.py#L73

Could be transformed to something like

def normal(
   img_in: np.ndarray,
   img_layer: np.ndarray,
   opacity: float,
   disable_type_checks: bool = False): 

It may be beneficial to be clearer about what kind of numpy arrays we expect, since there are some restrictions:

https://github.com/flrs/blend_modes/blob/4eca9470a210049db32b3fd2e95cc17d5b58e7bc/blend_modes/blending_functions.py#L94

It could be worth exploring solutions like https://github.com/ramonhagenaars/nptyping, since I don't think numpy type hints are supported by Python natively at this point.