You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to type-hint collections.UserList subclasses? #718
Runtime error: TypeError: 'ABCMeta' object is not subscriptable userList
How do I correctly type-hint SerializableItems - list of objects of what types?
This works for me, but line self.data: List[SerializableItem] does not seem the right thing to do.
This is due to a limitation of Python 3.6. The UserList is declared in the typeshed stubs as a generic class, so it is expected to have a type argument. But at runtime, Python 3.6 didn't support this. It was fixed in Python 3.7.
Your workaround will avoid the runtime error, but it has the side effect of not providing full autocomplete because the type checker has effectively been told that the class inherits from UserList[Any].
I don't see a good solution here other than to upgrade to Python 3.7.
Gethin Davies (@grddavies), since this issue is closed, please create a new issue describing what you are seeing. Linking your new issue to this one would be helpful.
Activity
erictraut commentedon Dec 11, 2020
This is due to a limitation of Python 3.6. The
UserListis declared in the typeshed stubs as a generic class, so it is expected to have a type argument. But at runtime, Python 3.6 didn't support this. It was fixed in Python 3.7.Your workaround will avoid the runtime error, but it has the side effect of not providing full autocomplete because the type checker has effectively been told that the class inherits from
UserList[Any].I don't see a good solution here other than to upgrade to Python 3.7.
grddavies commentedon Mar 15, 2022
I'm still having this issue with python 3.8.10
debonte commentedon Mar 15, 2022
Gethin Davies (@grddavies), since this issue is closed, please create a new issue describing what you are seeing. Linking your new issue to this one would be helpful.