'type' object is not subscriptable at function definition

Viewed 290

I've defined a function like this

def map_json_to_item_dictionary(json: dict[str, dict]) -> dict[int, Any]:
    result: dict[int, Any] = {}

    return result

but have an exception 'type' object is not subscriptable at function definition

PyCharm also prompt an exception Class 'type' does not define '__getitem__', so the [] operator cannot be used on its instances

Look like python try to access something from dict.

What I made wrong?

1 Answers

You'll need to import Dict and Any from the typing module:

from typing import Dict, Any

def map_json_to_item_dictionary(json: Dict[str, dict]) -> Dict[int, Any]:
    result: Dict[int, Any] = {}

    return result

Related