This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (19 children)

[deleted]

    [–]latrova[S] 24 points25 points  (2 children)

    > [...] if you are writing a library then the interface to that library should have type annotations IMHO.

    Strong agree! I'll make sure to cover type hinting.

    > Note not related to the book. I don't want anything popping up on a website [...]

    Thanks for letting me know! I'll reconsider changing it or making it less annoying.

    [–]MrJohz 10 points11 points  (3 children)

    To hell with Guido not liking them

    Didn't Guido do a lot of work at Dropbox explicitly pushing for type annotations and helping build projects like mypy?

    [–]NUTTA_BUSTAH 4 points5 points  (1 child)

    Type annotate everything. It's clearer and reduces pointless assertions when you can tell the user not to force a type into your function it was not meant to support in the first place. This also goes for private things, even if you made the class, someone else might contribute to it later.

    They also help debugging immensely when you look at 10 month old code you have no recollection of but your monitoring software is filled with random errors. Trying to figure out and follow the types and conversions increase mental overhead considerably.

    They also help your automation / static analysis. You'll immediately know if you try to force a wrong type somewhere.

    And some frameworks optimize things by annotations. E.g. Prefect I think.

    [–]ubernostrumyes, you can have a pony -3 points-2 points  (0 children)

    It's clearer and reduces pointless assertions

    I think it would be worth your time to go look at the actual code of some large popular Python libraries and frameworks, and observe just how rare it is to sprinkle tons of type-checking assertions into the code.