I begin to like sprinkling a few PEP 484 type hints in my Python code. Not necessarily because my code is laden with undetectable bugs and I want to use static type checking to help; it’s mainly because it makes the code more self-explanatory. It is a manifestation of the Zen of Python that “explicit is better than implicit”.
Here’s a little example. Compare the Python snippet
def filter_substr(strlst: List[str], substr: str) -> List[str]:
return list(filter(lambda s: substr in s, strlst))
with the equivalent Standard ML one
fun filter_substr(strlst: string list, substr: string): string list =
List.filter (String.isSubstring substr) strlst
Now I can pretend that I’m writing SML in Python.