小编jet*_*een的帖子

类型错误: | 不支持的操作数类型:“type”和“NoneType”

from dataclasses import dataclass

@dataclass
class InventoryItem:
    """Class for keeping track of an item in inventory."""
    name: str | None = None
    unit_price: float
    quantity_on_hand: int = 0
Run Code Online (Sandbox Code Playgroud)

类型错误: | 不支持的操作数类型:“type”和“NoneType”

Python 3.9

我认为问题是使用最新版本的python,如何解决。

我尝试使用“或”,但没有帮助

python typing nonetype

7
推荐指数
1
解决办法
2万
查看次数

标签 统计

nonetype ×1

python ×1

typing ×1