by inlineint · 9y ago · 0 comments
It is possible to add annotations to your code like
class Foo:
x: int
# ...
and then run type checks using `mypy`, so that for the annotated code probability of the "passes the checks => won't crash the runtime" case is much larger.So this might be helpful for code you wrote, but not anywhere it interfaces with other peoples' code (which, in my opinion, is probably the most important place to check for type errors).
IDEs like PyCharm can use those and other methods to find most typing issues. In practice this is very effective for most "boring" Python code, but if you get really clever it falls over completely.
from typing import Dict
Foo = Dict[int:str]
def __init__(self, name:str, balance=0.0):
"""Construct a Klass."""
self.myfoos = {} # type: Foo
I _think_ that's right... close anyway