on-internet
← Community

How to import List from typing module to recognize the type List[int] in Class?

Stack Overflow ·

While running my python3 code, I am getting the below error: 'TypeError: 'type' object is not subscriptable' System unable to recognize typing module having List parameter while I am trying to set __init__ class argument as List[int] I had installed typing.py module via pip and trying to import typing Even then system not recognizing List[int] type in the Class definition. Below is the code for the same, from typing import List class newcls: def __init__(self, a: int,arr: list[int]): self.a=a self.arr=arr def new1(self): print('a=',self.a) print(self.arr) obj1=newcls(1,[1,2,3]) obj1.new1() And

Comments

Sign in or sign up to comment and upvote.

No comments yet.