[英]Can you give an example for a NESTED TypedDict in class notation?
我想輸入設置並遇到這個答案和 TypedDict 但無法讓它與嵌套結構一起工作。
假設以下 dict,我怎樣才能最好地添加打字?
{
"global": {
"region": "eu-central-1",
},
"env": {
"dev": {
"name": "dev.local",
},
"prod": {
"name": "prod.world",
}
}
}
PS:我也有興趣,如果你有答案,如何用數據類做到這一點?
嘗試這樣的事情:
from typing import TypedDict
class Env(TypedDict):
name: str
class Region(TypedDict):
region: str
class EnvDescr(TypedDict):
global: Region
dev: Env
prod: Env
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.