Python3.10 的 int 和 float 有什么隐性转换
在 blender3.1
的更新日志关于 Python api
的部分看到了下面的内容:
Python 3.10
Python has been upgraded from version 3.9 to 3.10, there are some changes that may impact script authors.
- Python 3.10 no longer implicitly converts floats to int's (issue linked). This means functions that previously accepted float typed values will raise a type error.
Floating point arguments must now be explicitly converted to integers (see example commits (rBAbb62f10, rBA7476c1a).
翻译一下就是:
Python 3.10
Python已经从3.9版本升级到3.10,有一些变化可能会影响到脚本作者。
Python 3.10 不再隐含地将浮点数转换为整数(问题链接)。这意味着以前接受浮点类型值的函数将引发一个类型错误。
浮点参数现在必须明确地转换为整数 (参见示例提交 (rBAbb62f10, rBA7476c1a)。
啥意思?是改了 feature
还是 修了 bug
?
bpo-37999: No longer use int in implicit integer conversions.
No longer use implicit convertion to int with loss
回答:
REF: https://docs.python.org/3/wha...
Builtin and extension functions that take integer arguments no longer accept
Decimal
s,Fraction
s and other objects that can be converted to integers only with a loss (e.g. that have the__int__()
method but do not have the__index__()
method).
以上是 Python3.10 的 int 和 float 有什么隐性转换 的全部内容, 来源链接: utcz.com/p/938414.html