Search notes:

Python: __annotations__

__annotations__ is a dict that provides some annotations about global(?) variables, classes, class attributes, function parameters and return types.
__annotations__ is one of the names that is present in the top level scope (__name__ == '__main__') as returned by dir().

Supplying a function with an annotation about its return type

The special syntax def funcName() -> type adds the key 'return' to the __annotations__ dictionary. The value for this key is the specified type:
def sayHello() -> str:
    return 'hello world'

print('sayHello() is supposed to return a {}'.format(sayHello.__annotations__['return'].__name__))
#
#  sayHello() is supposed to return a str
Github repository about-Python, path: /dunders/__annotations__/def-1.py
It should be noted that the annotated type is not enforced at runtime:
def Func() -> int:
    return 'haha, not an int'

print(Func())
Github repository about-Python, path: /dunders/__annotations__/def-2.py

Supplying annotations about a function parameter

A function parameter is annotated with a colon (:) followed by the annotation.
def F(num: 'A number',
      txt: 'A text'   ='Hello World'):

    print('num:', num)
    print('txt:', txt)
    print('')

F(42)
F(txt = 'good bye', num = 99)

print('Annotations:')
for annot, val in F.__annotations__.items():
    print('{:4s}: {}'.format(annot, val))
Github repository about-Python, path: /dunders/__annotations__/def-param.py

See also

__doc__ and docstrings.
Other dunders

Index