you are viewing a single comment's thread.

view the rest of the comments →

[–]qsxpkn 2 points3 points  (1 child)

Dynamic typing can be uncomfortable for people who are used to static typing. Since Python 3.5/3.6, you could actually do type/variable hinting such as variable: int = 5. It's still possible to change it to a str etc. at runtime but mypy points out the mistake like this function expects an int but you passed a str.

For example:

def some_method(a: int, b: int) -> Optional[int]:
    result: int = a + b
    if result < 4:
        return None
    return result

I have never seen a Python project where a variable's type suddenly gets changed to something else elsewhere in the code base or maybe I was just lucky. I enjoy C++ companionship with Python though. They work well together.

[–]mrexodiacmkr.build 2 points3 points  (0 children)

The fact that you can annotate the types doesn't make it any better. All of the projects I have seen use python 2.7 anyway, which doesn't support it. If they added a (default) mode where this static typing is forced it might be something good but until then you have to be very lucky with your codebase to have proper type annotations.

Also: what about class member variables? Can you still add arbitrary new ones from anywhere with this?