8000 `builtins.sum`: Items in the iterable must support addition with `int` if no `start` value is given by AlexWaygood · Pull Request #8000 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

builtins.sum: Items in the iterable must support addition with int if no start value is given #8000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 13, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix
  • Loading branch information
AlexWaygood committed Jun 8, 2022
commit b00b2d6312c8b780e5648f69c8b70f161b7f3cd4
12 changes: 6 additions & 6 deletions test_cases/stdlib/builtins/test_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@


class Foo:
def __add__(self, other: Any) -> Foo:
def __add__(self, other: Any) -> "Foo":
return Foo()


class Bar:
def __radd__(self, other: Any) -> Bar:
def __radd__(self, other: Any) -> "Bar":
return Bar()


class Baz:
def __add__(self, other: Any) -> Baz:
def __add__(self, other: Any) -> "Baz":
return Baz()

def __radd__(self, other: Any) -> Baz:
def __radd__(self, other: Any) -> "Baz":
return Baz()


Expand All @@ -30,7 +30,7 @@ def __radd__(self, other: Any) -> Baz:

assert_type(sum([["foo"], ["bar"]], ["baz"]), List[str])

assert_type(sum([Foo(), Foo()], start=Foo()), Foo)
assert_type(sum([Foo(), Foo()], Foo()), Foo)
assert_type(sum([Baz(), Baz()]), Union[Baz, Literal[0]])

# mypy and pyright infer the types differently for these, so we can't use assert_type
Expand All @@ -44,7 +44,7 @@ def __radd__(self, other: Any) -> Baz:
sum([["foo"], ["bar"]]) # type: ignore[list-item]
sum([("foo",), ("bar", "baz")]) # type: ignore[list-item]
sum([Foo(), Foo()]) # type: ignore[list-item]
sum([Bar(), Bar()], start=Bar()) # type: ignore[call-overload]
sum([Bar(), Bar()], Bar()) # type: ignore[call-overload]
sum([Bar(), Bar()]) # type: ignore[list-item]

# TODO: these pass pyright with the current stubs, but mypy erroneously emits an error:
Expand Down
0