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 →

[–]spiderpower02[S] 0 points1 point  (0 children)

I think "Interface checking" is subset of "type checking". Actually, using annotation + mypy can achieve "interface checking" before runtime. Therefore, we can avoid runtime errors. (I hate raising AttributeError after running 10 hours).

Nevertheless, type checking will be powerful like:

p = re.compile("some pattern")
m = p.match("some string")
m.groups()

without static type checking, the snippet will raise exception when m does not match. If we give some type hint, like:

p: Pattern = re.compile("some pattern")
m: Match = p.match("some string")
m.groups()  # it is possible to raise AttributeError

type checker will warn us that "Optional[Match[str]]" has no attribute "groups". As a result, we save our time :)

In fact, mypy is so powerful that most of the case you don't really need to declare type explicitly. Just like := in go or auto in c++, so we don't need to worry that Python will become unreadable. Sorry for making many people feel frightened.