-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Labels
project: infrastructuretypeshed build, test, documentation, or distribution relatedtypeshed build, test, documentation, or distribution related
Description
I just updated MyPy in Jinja, and had to ignore the return type of sum
in one of my functions because MyPy started saying it wasn't compatible with the TypeVar
I was using. pallets/jinja@a24df26
I see a recent change related to the return type of sum
: #7578. Is this a bug in typeshed/mypy, or is there a better way I should be annotating that function in Jinja?
V = t.TypeVar("V")
def sync_do_sum(
environment: "Environment",
iterable: "t.Iterable[V]",
attribute: t.Optional[t.Union[str, int]] = None,
start: V = 0, # type: ignore
) -> V:
if attribute is not None:
iterable = map(make_attrgetter(environment, attribute), iterable)
return sum(iterable, start) # type: ignore[no-any-return, call-overload]
src/jinja2/filters.py:1295: error: Returning Any from function declared to return "V" [no-any-return]
src/jinja2/filters.py:1295: error: No overload variant of "sum" matches argument types "Iterable[V]", "V" [call-overload]
src/jinja2/filters.py:1295: note: Possible overload variants:
src/jinja2/filters.py:1295: note: def [_SumT <: _SupportsSum] sum(Iterable[_SumT]) -> Union[_SumT, Literal[0]]
src/jinja2/filters.py:1295: note: def [_SumT <: _SupportsSum, _SumS <: _SupportsSum] sum(Iterable[_SumT], _SumS) -> Union[_SumT, _SumS]
Found 2 errors in 1 file (checked 25 source files)
Metadata
Metadata
Assignees
Labels
project: infrastructuretypeshed build, test, documentation, or distribution relatedtypeshed build, test, documentation, or distribution related