Tla*_*-ES 0 python python-dataclasses python-typing pydantic
你好我正在使用Python 3.8
我正在实现一个带有修复列表的数据类,为了做到这一点,我有以下代码:
from dataclasses import dataclass
from typing import Annotated, List, ValueRange
from pydantic import validate_arguments
@validate_arguments
@dataclass
class WorldArea:
...
data: Annotated[List[float], ValueRange(1, 3)]
...
Run Code Online (Sandbox Code Playgroud)
这个想法是数据将是一个包含 1、2 或 3 个元素的列表,正如您所看到的,我正在使用 Annotated 和 ValueRange,但是当我执行时,我收到以下错误:
文件“a.py”,第 2 行,来自键入导入列表,ValueRange ImportError:无法从“打字”导入名称“注释”
文件“a.py”,第 2 行,来自键入导入列表,ValueRange ImportError:无法从“打字”导入名称“ValueRange”