2 ms·
> Python is very much not type safe It's strongly typed and mypy adds static typing support too (so you end up with a strong gradually typed language). Would y
by boramalper 8y ago
> Python is very much not type safe
It's strongly typed and mypy adds static typing support too (so you end up with a strong gradually typed language). Would you consider it insufficient?
- jchw 8y ago>It's strongly typed Sure, it's strongly typed, but I think that's irrelevant, at least if my understanding of the term 'type safe' is correct. From Wikipedia: >In computer science, type safety is the extent to which a programming language discourages or prevents type errors. The thing is, a Python program that causes a type error is valid, even if it crashes. TypeError is strictly a runtime error. To me, that is the epitome of not having type safety. Of course pretty much everything is runtime in Python, by virtue of it being a script language. So you really would need a type checking stage, like TypeScript. But... >mypy adds static typing support too In my opinion, MyPy is not sufficient to represent common usages of Python's type system. Even with the recent addition of structural typing, many Python programs just do things that are not easily typed. An example would be, in Django, many things in the core directly patch the Request object, and there's really not a terribly sane way to represent this in a reasonable type system. I feel Python encourages all kinds of type craziness, with metaclasses, 'file-like' objects, etc. Opinions aside... Since MyPy is not part of Python itself (yet?) it is unfair to call the Python language 'type safe' simply by virtue of a type checker existing, for the same reason one wouldn't call JavaScript type safe (I do acknowledge that both of them definitely have a chance of becoming 'official', but neither have yet, and that's the important part.) Not strictly related, but there are also other type checkers, too: At Google, we've got pytype (https://github.com/google/pytype https://github.com/google/pytype) and Facebook has pyre-check (https://github.com/facebook/pyre-check https://github.com/facebook/pyre-check). I've tried neither myself.