Skip to content

Commit

Permalink
Revert sum literal integer change (#13961)
Browse files Browse the repository at this point in the history
This is allegedly causing large performance problems, see 13821

typeshed/8231 had zero hits on mypy_primer, so it's not the worst thing
to undo. Patching this in typeshed also feels weird, since there's a
more general soundness issue. If a typevar has a bound or constraint, we
might not want to solve it to a Literal.

If we can confirm the performance regression or fix the unsoundness
within mypy, I might pursue upstreaming this in typeshed.

(Reminder: add this to the sync_typeshed script once merged)
  • Loading branch information
hauntsaninja committed Oct 29, 2022
1 parent 74e0dff commit 184add9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1569,11 +1569,11 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
# Instead, we special-case the most common examples of this: bool and literal integers.
if sys.version_info >= (3, 8):
@overload
def sum(__iterable: Iterable[bool | _LiteralInteger], start: int = ...) -> int: ... # type: ignore[misc]
def sum(__iterable: Iterable[bool], start: int = ...) -> int: ... # type: ignore[misc]

else:
@overload
def sum(__iterable: Iterable[bool | _LiteralInteger], __start: int = ...) -> int: ... # type: ignore[misc]
def sum(__iterable: Iterable[bool], __start: int = ...) -> int: ... # type: ignore[misc]

@overload
def sum(__iterable: Iterable[_SupportsSumNoDefaultT]) -> _SupportsSumNoDefaultT | Literal[0]: ...
Expand Down

0 comments on commit 184add9

Please sign in to comment.