You may encounter an issue with Python 3.5+ versions while defining variables, this is because Python 3.6 introduced a new syntax under PEP526 for annotating the variables.


>>> items = [{}]

The above line causes an error called error: Need type annotation for items this is simply because of the PEP526.

Fix Need type annotation for variable in python:

Define the type of the variables with comments or variable:type expression.

from typing import Any, List, Dict

items = [{}]  # type: List[Dict[str, Any]]
name = ''  # type: str
i = 10 # type: int


items: List[Dict[str, Any]]
name: str = ''
i: int = 10

It can be worked with class and instance variables too.



Happy Learning 🙂