'Type error = 'type' object is not subscritable points: list[Point] = field(init=False) [duplicate]
I'm trying to reproduce the implementation of a method I found on Github. But I'm having a type error.
class Instance:
path: str = False
size: int = 10
dimension: int = 10
points: list[Point] = field(init=False)
origin: Point = Point(0, 0, 0)
finish: Point = Point(0, 0, 0)
nb_vehicules: int = 2
max_distance: float = 100
max_capacity: int = 100000
poid_min: int = 2
poid_max: int = 10
The error refers to the line points: list[Point] = field(init=False).
Point is a class that was defined before:
class Point:
x: float
y: float
poid: int
Solution 1:[1]
Your Python version is outdated.
Please update your Python to version 3.9+, that's when built-in types started supporting generic subscription.
Otherwise, you can use the typing module like so:
from typing import List
...
points: List[Point] = field(init=False)
...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Bharel |
