pytype icon indicating copy to clipboard operation
pytype copied to clipboard

Spurious pass when Sequence[int | None] passed to behavior requiring Iterable[not-None]

Open nathanielmanistaatgoogle opened this issue 5 months ago • 2 comments

With pytype-2024.9.13 the file content

Q = sum([0, 1, 2, 3, None])
T = sum([None, 3])
W = sum([None, None])

is flagged with

temp-2024-09-14-pytype/haha.py:3:1: error: in <module>: Built-in function sum was called with the wrong arguments [wrong-arg-types]
         Expected: (iterable: Iterable[_Summable])
  Actually passed: (iterable: List[None])
  Attributes of protocol _Summable are not implemented on None: __add__

W = sum([None, None])~~~~~~~~~~~~~~~~~~~~
W = sum([None, None])



For more details, see https://google.github.io/pytype/errors.html#wrong-arg-types

but that's insufficient; all three of those lines ought have been flagged with wrong-arg-types (none of those three lines will evaluate without raising a TypeError).