matrix-org / sygnal

Sygnal: reference Push Gateway for Matrix
Apache License 2.0
160 stars 144 forks source link

Type hints for apnstruncate, apnspushkin, notifications, and gcmpushkin #264

Closed H-Shay closed 2 years ago

H-Shay commented 2 years ago

Here is my first try at adding some type hints to the below files in Sygnal, and making very minor modifications to the code to silence some mypy errors (like assert is not None). A very small handful of errors remain (less than 4 I think?) across the files I changed but silencing them seemed like it might require more modification to the code, and I wanted to make sure that everything I had here was correct before I started tackling those. I think that these are mostly correct but I find typing to be a little difficult so it is entirely possible I have gotten some things wrong.

squahtx commented 2 years ago

For the tuple index out of range complaints, we might want to define Choppable = Union[Tuple[Literal["alert", "alert.body"]], Tuple[Literal["alert.loc-args"], int]] (ie. Choppable is either ("alert",), ("alert.body",) or ("alert.loc-args", int)) then mypy should be clever enough to figure things out.