Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type hint for a dict gives TypeError: 'type' object is not subscriptable [duplicate]

memo: dict[int, int] = {0: 0, 1: 1} # *our base cases*

returns the following error:

TypeError: 'type' object is not subscriptable
like image 340
Robert Li Avatar asked Nov 29 '19 08:11

Robert Li


1 Answers

I guess you should use Dict, e.g.:

from typing import Dict

memo: Dict[int, int] = {0: 0, 1: 1}

In your case, you were using dict which is of type type

>>> type(dict)
<class 'type'>
>>> type(Dict)
<class 'typing._GenericAlias'>
like image 119
David_Zizu Avatar answered Sep 24 '22 13:09

David_Zizu