Is there any advantage to using the 'type hint' notation in python?
import sys
def parse(arg_line: int) -> str:
print (arg_line) # passing a string, returning None
if __name__ == '__main__':
parse(' '.join(sys.argv[1:]))
T
o me it seems like it complicates they syntax without providing any actual benefit (outside of perhaps within a development environment). Based on this:
type
constraints within the language itself?I also don't see this much in the python codebase itself as far as I can tell -- most types are enforced manually, for example: argparse.py
and any other files I've glanced at in https://github.com/python/cpython/blob/3.7/Lib/.
Almost certainly not, and definitely not before the next major version.
Type hints can be used by modules like
or external libraries like
to add additional type-related features (in this case, dispatching function calls based on name and type, not just name).