DEV Community

Serhat Teker
Serhat Teker

Posted on • Originally published at tech.serhatteker.com on

Type Hinting for Dictionaries in Python

We can use generic version of dict: Dict, to declare the dictionary type in
python:

from typing import Dict


def get_request(self) -> Dict[str, str]:
    ...


def validate(request: Dict[str, str]) -> bool:
    ...
Enter fullscreen mode Exit fullscreen mode

However this is deprecated since version 3.9. We can use directly dict:



def get_request(self) -> dict[str, str]:
    ...


def validate(request: dict[str, str]) -> bool:
    ...

Enter fullscreen mode Exit fullscreen mode

For more info: Dict

All done!

Top comments (0)