Hacker News new | past | comments | ask | show | jobs | submit login

Python has static typing? Since when? In what form?



Python 3 supports type annotations natively, and the mypy tool is an external typechecker that you can run just like any other static analysis tool during your build.


That isn't static typing.


- You can specify types

- Types are checked before run time

- Type errors are reported

If that's not static typing, what is?


If Python were statically typed:

- Most Python expressions and standard library functions would have (nontrivial) types

- It would be unusual for a Python library to come without (nontrivial) types

- It would be unusual for Python code containing type errors to be distributed

- Many classes of runtime errors (e.g. no such method) would be unusual in Python code that does not contain type errors


Python is not statically typed. Mypy adds a layer of static typing on top of Python.


Right, but it's misleading to say "Python has static typing", because while an implementation of static typing in Python exists, the vast majority of the Python ecosystem doesn't use it.


That's why I didn't say 'Python has static typing', I said:

> Python 3 supports type annotations natively

And:

> the mypy tool is an external typechecker that you can run just like any other static analysis tool

I think I was pretty clear that Python is not statically typed.


What is a static or strong type system is sort of up for debate, the terms are not well defined. Not OP, but IMO type annotations are static but not strong. I'd consider a strong type system one that enables you to encode additional invariants in the types, with sum and product types being perhaps the minimal requirement.


This argument isn't convincing. These artifacts are hints that can be ignored, not constraints to the python interpreter. It seems to me a bit like arguing that the existence of Coverity (and other static analysis tools) means C is as safe as Rust.


The types were never meant for the Python interpreter, they were meant as documentation and as input for static analysis tools. Mypy just happens to be a static typechecker that takes advantage of the type annotations.

Just because mypy is optional doesn't mean it's not static typing.


Whatever you want to call it, it's a lot more static than it used to be.





Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: