gpt4 book ai didi

字符串连接上的 Python 3.6 与 3.5 TypeError 消息

转载 作者:太空狗 更新时间:2023-10-29 18:07:33 27 4
gpt4 key购买 nike

'Hello ' + 1 在 Python 3.5 和 3.6 上不返回相同的错误消息:

  • Python 3.5.2:TypeError:无法将“int”对象隐式转换为 str
  • Python 3.6.0:TypeError:必须是 str,不是 int

这是一个简单的措辞变化还是背后有更微妙的东西?

最佳答案

这只是一些涉及字符串对象的代码清理。它还在使用不兼容的对象时对错误消息进行了一些更改,以使它们“提供更多信息”。

参见: Issue 26057 - Avoid nonneeded use of PyUnicode_FromObject() 如果您有兴趣,它会引入此更改。

这里没有什么微妙之处,它仍然是非法的,所有,作者将错误消息更改为他认为更清楚的内容。

编辑:我创建了 Issue 29116 - Make str and bytes error messages on concatenation conform with other sequences 来解决这个特定的消息,同时也解决字节类型的错误消息,当我们用它们做一些愚蠢的事情时,它们有类似的冗长响应:

>>> b'' + ''
TypeError: can't concat bytes to str

关于字符串连接上的 Python 3.6 与 3.5 TypeError 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41388606/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com