microsoft / pyright

Static Type Checker for Python
Other
13.12k stars 1.4k forks source link

Lambda type error #8714

Closed danielpopescu closed 1 month ago

danielpopescu commented 1 month ago

from __future__ import annotations

import operator
from typing import Callable

def safe_fold_left[T, U](lst: list[T], init: U, f: Callable[[U, T], U]) -> U:
    for e in lst:
        init = f(init, e)
    return init

x = safe_fold_left([1, 2, 3, 4], 1, operator.mul) # this is fine...
y = safe_fold_left([1, 2, 3, 4], 1, lambda x, y: x * y) # type error here

Pyright 375, python 3.12 TY

erictraut commented 1 month ago

This is addressed in pyright 1.1.376.