DEV Community

Lam Nguyen
Lam Nguyen

Posted on

Answer: How to set the python type hinting for a dictionary variable?

Dict takes two "arguments", the type of its keys and the type of its values. For a dict that maps strings to integers, use

def doSomething(value: Dict[str, int]):

The documentation could probably be a little more explicit, though.

</p>
Enter fullscreen mode Exit fullscreen mode





from typing import Dict

def doSomething(Some_Dict: Dict[str, SomeObject]):

then voila! your IDE will suggest the members of each value (SomeObject) in the dictionary!

Top comments (0)