3

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?

Red
  • 26,798
  • 7
  • 36
  • 58
Alex Klimashevsky
  • 2,457
  • 3
  • 26
  • 58
  • [Type hinting a collection of a specified type](https://stackoverflow.com/questions/24853923/type-hinting-a-collection-of-a-specified-type) – khelwood Nov 23 '20 at 12:40

1 Answers1

2

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

Red
  • 26,798
  • 7
  • 36
  • 58