python-microscope / microscope

Python library for control of microscope devices, supporting hardware triggers and distribution of devices over the network for performance and flexibility.
https://www.python-microscope.org
GNU General Public License v3.0
69 stars 41 forks source link

add type annotations #108

Open carandraug opened 5 years ago

carandraug commented 5 years ago

Abstract Base Classes force a class to have a specific list of methods and attributes. However, it does not enforce the correct function signature and return values for those methods.

Type annotations and the typing module were introduced in Python 3.5 and look like this:

def get_position(self) -> int:
# ...
def set_position(self, position: int) -> None:
# ...
def _raise_status(self, func: typing.Callable) -> None:

Documentation for the typing module states that it was added in provisional basis and may change between minor versions. I have checked changes between 3.5 and 3.9 and the changes don't seem major.

I have spoken with @mickp about it some time ago about using it on microscope and we agreed that we could add them slowly as we go, no need to spend the time annotating everything we already have. If Python ever decides to remove the typing module, or make many changes on how it works, it shouldn't be that much work to remove or change them anyway.