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

Python is strongly-typed. With its built-in type annotation syntax and a checker like mypy or pyright, it is statically-typed, too.


My experience with mypy has been pretty negative.

Not because mypy is bad per se, but it just doesn't flow into a Python workflow naturally. Every time you try to interact with an external module without these annotations you immediately lose all the advantages of statically typed programs.

For me, Python with annotations just doesn't make sense, at that point I would prefer to program in Rust or Java.


For external modules, you can generate stub files that contain inferred and/or manually supplied annotations[0].

[0] https://mypy.readthedocs.io/en/stable/stubgen.html


Type annotation and mypy, while better than nothing, is a hack and doesn't always properly work so in a real codebase you'd be using `# type: ignore` quite often even if all of your downstream code is properly type-annotated and mypy-typechecked.

Most importantly though, it does not make Python statically typed, by no means. It just lets you lint stuff in a semantic fashion (which is helpful, no doubt), improves auto-completion and removes the need of listing type requirements in docstrings.


A bonus for writing strongly typed code and using a small/safe subset of python is that you can transpile it to languages like rust or kotlin




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

Search: