This is okay, but sometimes it can be confusing, and suddenly Python’s flexibility becomes more of a nuisance than anything else.
Since 3.5, we could specify types, but it was pretty cumbersome. This update has truly changed that, let’s use an example:
add_int function, we clearly want to add the same number to itself (for some mysterious undefined reason). But our editor doesn’t know that, and it is perfectly okay to add two strings together using
+ — so no warning is given.
What we can now do is specify the expected input type as
int. Using this, our editor picks up on the problem immediately.
We can get pretty specific about the types included too, for example:
Type hinting can be used everywhere — and thanks to the new syntax, it now looks much cleaner: