Skip to content
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

mypy error: Cannot infer type argument 1 of "sum" #3889

Closed
levsa opened this issue Aug 30, 2017 · 1 comment
Closed

mypy error: Cannot infer type argument 1 of "sum" #3889

levsa opened this issue Aug 30, 2017 · 1 comment

Comments

@levsa
Copy link

levsa commented Aug 30, 2017

When using sum() to concatenate lists, mypy fails to infer the type argument of "sum", even if types are declared explicitly.

sum([[1],[2],[3]], []

or

foo: List[List[int]] = [[1],[2],[3]]
sum(foo, [])

both give:

error: Cannot infer type argument 1 of "sum"

@JukkaL
Copy link
Collaborator

JukkaL commented Aug 30, 2017

This looks like a duplicate of #230. Here are two workarounds:

  • You can use a local variable to hold the empty list and annotate the variable (empty: List[int] = []) and pass the variable as the second argument to sum.
  • You can cast the empty list to the desired type: sum(foo, cast(List[int], []))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants