Currently the stub for the sum built-in allows any iterable as an argument
|
@overload |
|
def sum(__iterable: Iterable[_T]) -> _T | Literal[0]: ... |
|
|
|
if sys.version_info >= (3, 8): |
|
@overload |
|
def sum(__iterable: Iterable[_T], start: _S) -> _T | _S: ... |
|
|
|
else: |
|
@overload |
|
def sum(__iterable: Iterable[_T], __start: _S) -> _T | _S: ... |
This means mypy has no issue with:
Which results in this error at runtime:
TypeError: unsupported operand type(s) for +: 'int' and 'str'
context: I was introducing someone to mypy and used the example above as something that mypy should flag, but turns out it wasn't being flagged so logging here.
Currently the stub for the
sumbuilt-in allows any iterable as an argumenttypeshed/stdlib/builtins.pyi
Lines 1480 to 1489 in ae6ff79
This means mypy has no issue with:
Which results in this error at runtime:
context: I was introducing someone to mypy and used the example above as something that mypy should flag, but turns out it wasn't being flagged so logging here.