In my vscode setup with mypy strict, pylance basic and python 3.9 though, type hints all days for me. I personally forget the arguments types like 1 second after I write the function. Maybe I'm conditioned by typed python.
Leetcode codes usually have simpler data structure and without 3rd party libraries so that's even easier to add types for.
Edit: Oh looks like Leetcode python code template has type hints
when you paste this code, it's infinitely more readable out of its original context with those hints.
def max_width_of_vertical_area(points):
xs = sorted(x for x, _ in points)
return max(x2-x1 for x1, x2 in zip(xs, xs[1:]))
Just seems easier...Though I spend most my time writing Swift code, which definitely influences my preference.
Would you say this is "less readable substantially" than your example?
def max_width_of_vertical_area(points):
# type points: List of List of int
xs = sorted(x for x, _ in points)
return max(x2-x1 for x1, x2 in zip(xs, xs[1:]))Are Python type hints able to specify types like that?
My experience even before that was mostly with PyDev in eclipse. The trick back then was identifying good spots to add type-hints, afterwhich the "IDE" would take over and propagate them through the different variables and calls using static code analysis. It was surprisingly good and helped immensely with very few actual instances of types being hinted. Another one was PyCharm that would "save" or "cache" the types during debug/test runs and use them as type-hints without you explicitly having to define them.
Fancy example:
List[Dict[str, MyCustomTypeGeneric[str]]]
Which gives you a list of dictionaries with keys of type string, holding values MyCustomTypeGeneric with generic type str.
Yes, Iterable[Tuple[Number, Number]] is a valid type, though 2D points are probably Tuple[Real, Real] or just Complex, not Tuple[Number, Number].
Snake case.
this-is-called “kebab case”
ThisIsCalled “Pascal Case”