Adding python typehints to Klipper?

For any large codebase in Python I like working with typehints as they really assist by forcing bugs to surface when code is being written vs. getting runtime errors in the field. Additionally they are good at finding more subtle corner cases in the code where maybe a little used codepath returns the wrong type.

Typehints were made to be incrementally added to existing code, and currently you can run mypy with Python 3 to typecheck Python 2.7 w. typehints in the following style:

Python 3:

def embezzle(self, account: str, funds: int = 1000000, *fake_receipts: str) -> None:
    """Embezzle funds from account using fake receipts."""
    <code goes here>

is equivalent to the following in Python 2:

def embezzle(self, account, funds=1000000, *fake_receipts):
    # type: (str, int, *str) -> None
    """Embezzle funds from account using fake receipts."""
    <code goes here>

Do you folks see any value in typehints in general (I know I do), and whether adding them to Python 2 code in the style above, or delay until Python 3 is the norm? If there is enough interest I could stand up a branch with one module done for people to look at.


1 Like

Moved to the Developers category

I feel such a fool, thanks for moving it over.