When i wrote a python funtion below:
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
I got a waning on b[n] from IDE, which says:
Unexpected type(s): (int, bytes) Possible type(s): (SupportsIndex, SupportsIndex) (slice, Iterable[SupportsIndex] | bytes)
I'm totally confused: Why the index of array b should be a type of SupportsIndex? Is there any problem on simple int?
Apparently this is a bug in Pycharm:
It was present in 2021.2.3
and other versions
PyCharm 2022.1
do not have this bug.
But, it looks like that bug is back as of 2023.2.1 (Community Edition)
Try these workarounds (temporary solutions):
Go to
File -> Manage IDE Settings -> Restore Default Settings
Or
Disable warnings/ ignore warnings