aesara-devs / aehmc

An HMC/NUTS implementation in Aesara
MIT License
33 stars 6 forks source link

Add `KernelType` type annotation #72

Open rlouf opened 2 years ago

rlouf commented 2 years ago

[W]e could really use some type annotations for arguments like this. I honestly don't know the exact form of a valid kernel type (other than that it's a callable of some sort), so this is one instance where the type info really helps. In order to figure this out, I would have to trace where it's used in this codebase, and/or guess and check.

A custom type (alias) that explicitly ties together the functions in this library that construct valid kernel arguments is really all that's necessary to answer basic questions, so there's no need to delve much deeper than KernelType = Callable[[...], ...]—although something like KernelType = NewType("KernelType", Callable[[...], ...]) might be better for maintaining the "this function takes/outputs acceptable kernels" information when the local variable name KernelType isn't present in context (e.g. some Mypy reporting).

_Originally posted by @brandonwillard in https://github.com/aesara-devs/aehmc/pull/66#discussion_r915285566_