小编Evy*_*vyn的帖子

如何使用包含连字符的键定义 TypedDict 类

如何创建一个 TypedDict 类,该类支持包含连字符或字符串中支持的其他字符的键,例如下面示例中的“justify-content”。

from typing import TypedDict, Literal
from typing_extensions import NotRequired

class Attributes(TypedDict):
    width: NotRequired[str]
    height: NotRequired[str]
    direction: NotRequired[Literal["row", "column"]]
    justify-content: NotRequired[Literal["start", "end", "center", "equally-spaced"]]
Run Code Online (Sandbox Code Playgroud)

python typing python-typing

5
推荐指数
1
解决办法
1534
查看次数

标签 统计

python ×1

python-typing ×1

typing ×1