小编red*_*dia的帖子

如何键入提示 getter 仅允许 dict 的键?

我想知道如何使这个 getter 更加类型安全:

VALUES = {
   '1': 'One',
   '2': 'Two',
   '3': 'Three'
}


def get(key : str) -> str:
    return VALUES[key]
Run Code Online (Sandbox Code Playgroud)

str我希望有一个keyof VALUESand类型,而不是类型type(VALUES[key])

get('4')应该抛出无效类型警告,因为该键不存在。不确定这对于 Python 是否可行,因为我确实生活在 TypeScript 仙境中......:-)

TypeScript 正确的样子应该是这样的:

VALUES = {
   '1': 'One',
   '2': 'Two',
   '3': 'Three'
}


def get(key : str) -> str:
    return VALUES[key]
Run Code Online (Sandbox Code Playgroud)

python type-hinting keyof python-typing

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

设置要显示的表:块

我喜欢让我的表行为像块元素.我无法将其设置为宽度:100%,因为它确实有一些填充,这将导致100%+填充PX.

退房:http://jsfiddle.net/LScqQ

最后桌子做了我想要的,你能看到盒子阴影吗?但桌子上的孩子不喜欢那样^^

我猜THEAD里面的TH是问题所在.它们没有达到66%至33%的预期比率.

把招工广告...

css width css-tables

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

标签 统计

css ×1

css-tables ×1

keyof ×1

python ×1

python-typing ×1

type-hinting ×1

width ×1