Question: Does type hints increase the speed of the program (lack of need to do lazy type conversion), or does it only increase the speed of debugging?
Annotations don't do anything at runtime. Your program will be just as fast with type hints. What do you mean by "lazy type conversion"?
Annotations don't do anything at runtime
Well, that's not entirely true. You can inspect those annotations:
>>> def f(x: int, y: str) -> float: ... pass ... >>> f.__annotations__ { 'x': <class 'int'>, 'y': <class 'str'>, 'return': <class 'float'> }
that's why they were added to the language in the first place — type checking wasn't the only goal. But the interpreter doesn't do anything with the annotations on its own.
Fair response, so it is more like an error catching tool.
What do you mean by "lazy type conversion"
Sorry, was thinking of Javascript, as Python does not do that. programiz.com/javascript/type-conv... sitepoint.com/automatic-type-conve...
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Question: Does type hints increase the speed of the program (lack of need to do lazy type conversion), or does it only increase the speed of debugging?
Annotations don't do anything at runtime. Your program will be just as fast with type hints. What do you mean by "lazy type conversion"?
Well, that's not entirely true. You can inspect those annotations:
that's why they were added to the language in the first place — type checking wasn't the only goal.
But the interpreter doesn't do anything with the annotations on its own.
Fair response, so it is more like an error catching tool.
Sorry, was thinking of Javascript, as Python does not do that.
programiz.com/javascript/type-conv...
sitepoint.com/automatic-type-conve...