The typing module is a back port for earlier version of Python to infer input and output datatypes. I am having an issue getting it to work in Python 2.7.
import typing
def greeting(name): # type: (str) -> str
"""documentations"""
return ('Hello ' + name)
print(greeting.__annotations__) # fails because doesn't exist.
I've also tried this:
import typing
def greeting(name # type: str
):
# type: (...) -> str
"""documentations"""
return ('Hello ' + name)
And this:
import typing
def greeting(name):
# type: (str) -> str
"""documentations"""
return ('Hello ' + name)
This should create an __annotations__
property on the class according to PEP484, but I do not see this happening at all.
What am I doing wrong with the backport code?