Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The new type-hints sure: List[List[int]] (and you can do this to any arbitrary types or levels of nesting. See fancy example at the end.). But older iterations before the formal type-hint spec had varied/non-standard ways of doing it. Some machine-readable but others more for the user (like List of List of int). Even once the type-hint spec got approved, it was backported to older versions of python using docstrings.

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.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: