Example Code From Typing Library Causes Typeerror: 'type' Object Is Not Subscriptable, Why?
Considering to Python Docs for typing why code below isn't working? >>> Vector = list[float] Traceback (most recent call last): File '', line 1, in
Solution 1:
The ability to use the []
operator on types like list
for type hinting was added in 3.9.
https://docs.python.org/3/whatsnew/3.9.html#type-hinting-generics-in-standard-collections
In earlier versions it will generate the error you describe, and you need to import List
object from typing
instead.
Baca Juga
- Pyqt5 Cannot Update Progress Bar From Thread And Received The Error "cannot Create Children For A Parent That Is In A Different Thread"
- How Do I Type-hint That A Python Function Returns Instance Of Any Class Derived From A Superclass?
- What Are Built-in Python 3 Types That Can Be Compared To Each Other?
from typing importListList[float]
Post a Comment for "Example Code From Typing Library Causes Typeerror: 'type' Object Is Not Subscriptable, Why?"