Skip to content

set.union not working correctly #2013

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

Closed
za3k opened this issue Aug 11, 2016 · 4 comments
Closed

set.union not working correctly #2013

za3k opened this issue Aug 11, 2016 · 4 comments
Labels
false-positive mypy gave an error on correct code feature priority-2-low

Comments

@za3k
Copy link

za3k commented Aug 11, 2016

Code:
a = set().union(*[[1],[2],[3]]) # type: Set[int]

Expected:This should work fine
Result:

error: Argument 1 to "union" of "set" has incompatible type *List[List[int]]; expected Iterable[None]
error: Incompatible types in assignment (expression has type Set[None], variable has type Set[int])

I'm fairly new to mypy, so please let me know if this is user error.

@za3k
Copy link
Author

za3k commented Aug 11, 2016

Worth noting that this works:

base_set = set()  # type: Set[int]
a = base_set.union(*[[1],[2],[3]])```

@gnprice
Copy link
Collaborator

gnprice commented Aug 12, 2016

Thanks for the report! I think this is a case where our type inference within a statement/expression is a little too dependent on specific rules and consequently only able to reason through N layers of indirection but not N+1. We've talked about this before (/cc especially @ddfisher), but I'm not sure we have an issue squarely directed at it -- #1055 appears to be closest.

I'd certainly like to fix this kind of situation, preferably in a way that involves reducing the number of special cases, but I don't think we yet know precisely how to do that. For now, the workaround in your follow-up comment is the recommended approach -- fortunately it's usually not particularly cumbersome.

@gnprice gnprice added this to the Future milestone Aug 12, 2016
@gvanrossum gvanrossum removed this from the Future milestone Mar 29, 2017
@JukkaL JukkaL added false-positive mypy gave an error on correct code feature labels Jul 3, 2020
@djrochford
Copy link

djrochford commented Sep 20, 2020

Note that this:

a = set.union(*[{1},{2},{3}])

works fine. This may be a nice workaround in some situations.

@AlexWaygood
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-positive mypy gave an error on correct code feature priority-2-low
Projects
None yet
Development

No branches or pull requests

6 participants