DEV Community


Discussion on: Why I started using Python type annotations, and why you should too

epogrebnyak profile image
Evgeny Pogrebnyak

Liked to namedtuple example! My experience with annotations is quite limited though: I add simple types as a substitute for docstrings, but when it comes to compose types, eg list of dicts, importing typing module is not a habit for me yet. Mypy is not integrated to spyder, an IDE I use, so I do not get any benefits other than readibility. Annotations are not yet substitutes for strong typing, which is some of the promises of python 4, I think. I wish I had an option of using python as a strongly typed language.

florimondmanca profile image
Florimond Manca Author

Thanks! It's a shame that Spyder doesn't support type checking. I know Atom doesn't either (I use Atom at home and PyCharm at work) but it manages to use the annotations for autocompletion (i.e. displaying methods of an object annotated as a certain class), which is already pretty handy. Does Spyder's autocompletion support this as well?

If I may, I'm not sure "strong typing" is the correct word there — Python is a very strongly typed language. Everything has a type, even the type object itself!
However it is does not have "true" static typing, yet — and I don't think it ever should. Adding attributes/methods at runtime is one of the most powerful things dynamic typing allows, and that would have to go away with static typing.
However, if a very optional and controllable way of saying "this variable should never be assigned to a variable of type other than XYZ", I'd be interested as well. Not sure how much overhead that would create, though, as the interpreter would have to do checks on every assignments.
If you have resources on forecast static typing features for Python 4, I'd be glad to check them out! :)

matyashvladislav profile image
Forem Open with the Forem app