有没有办法将Python类型提示作为单元使用?type hint docs显示了一些示例,这些示例表明使用^{
Seconds = UnitType('Seconds', float)
Meters = UnitType('Meters', float)
time1 = Seconds(5)+ Seconds(8) # gives a value of type `Seconds`
bad_units1 = Seconds(1) + Meters(5) # gives a type hint error, but probably works at runtime
time2 = Seconds(1)*5 # equivalent to `Seconds(1*5)`
# Multiplying units together of course get tricky, so I'm not concerned about that now.
我知道存在用于单元的运行时库,但我好奇的是python中的类型提示是否能够处理其中的一些功能
答案不就在那里on the page你链接了吗
看起来,因为we can't pass a value, only a type, into a generic,所以不可能进行全维分析as available in Ada和implementable in C++
相关问题 更多 >
编程相关推荐