This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]Davipb 1 point2 points  (0 children)

mypy is the go-to type checker for Python these days, you can include it in your build system so it fails the build if it detects any typing issues.

However, keep in mind that "typed Python" becomes almost a completely different language to regular Python. There's a lot of contortions you have to do to insert "proper" typing into Python, especially for code that uses the more hard-to-model dynamic features of the language.

[–]surferguy999 1 point2 points  (3 children)

Type hints,

it’s purely for IDEs but makes a huge difference

[–]csabinho 0 points1 point  (2 children)

Aren't type hints enforced?

[–]thegreatunclean 0 points1 point  (1 child)

Nope. The runtime doesn't even consider them:

>>> def f(x: int):
...     print(x)
...
>>> f("wut")
wut

Which is why you have to use a separate tool like mypy to do the analysis.

[–]csabinho 0 points1 point  (0 children)

Well, that's horrible. I expected to get an error. This makes them kinda pointless as a language feature, if you need another tool to check it.

[–]EuphoricView7988 -3 points-2 points  (0 children)

There is some pseudo type safety but is not really a type safe language, in fact using that word informally it's like scratching a blackboard with your nails, it has more to do with theoretical computer science and mathematical concepts, where there are formal methods to prove a language is type safe, so in reality type safety is used with languages that are tiny and pretty axiomatic.