当我在下面编写一个Python函数时:
def readinto(self, b: bytearray) -> int:
n, size = 0, len(b)
while n < size:
try:
b[n] = next(self._it)
except StopIteration:
break
n += 1
return n
我从 IDE 中得到了 b[n] 的减弱,它表示:
意外类型:(int, bytes) 可能类型:(SupportsIndex, SupportsIndex) (切片, Iterable[SupportsIndex] | 字节)
我完全困惑了:为什么数组 b 的索引应该是 SupportsIndex 类型?简单的int有问题吗?
显然这是 Pycharm 中的一个错误:
它存在于
2021.2.3
和其他版本
PyCharm
2022.1
没有这个bug。
但是,看起来 bug 在 2023 年 2 月 1 日(社区版)又回来了
尝试这些解决方法(临时解决方案):
前往
File -> Manage IDE Settings -> Restore Default Settings
或者
Disable warnings/ ignore warnings