-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Improve unification of conditional expressions #1094
Comments
This looks like the type of the expression `([] if ... else children)`,
where children has type `List[Node]`, is inferred as `object` whereas it
should really be inferred as `List[Node]`. We should fix this. In the
meantime you can work around it by replacing `[]` with `cast(List[Node],
[])`. But that's a very verbose solution and mypy should do better.
|
The if..else expression doesn't propagate the type context (in your example A related way to fix this would be to use the type of the right operand as the type context for the first expression, in case the latter has an incomplete inferred type. This would have the benefit of not requiring a type annotation. I think that you could also work around the problem by rearranging the expression:
|
Well, in this case if the unification of empty list and List[Node] was the
latter we wouldn't even need to propagate the context.
…--Guido (mobile)
|
I keep running into this. The type of (a if x else b) where a and b don't have the same type often degenerates to object or some other useless type rather than the intersection of the two types. Latest example:
Also, e.g.in Python 2 mode:
In Python 3 mode this gives
|
I'm going to have a crack at this. |
…as an empty list/set/dict. Fix #1094.
I have this snippet of code
if I use mypy I get
I think it's something related to the children parameter setted to None, but the problem is... how do I specify that yes, maybe the children parameter can be None, but self.children, by construction is always a List of Nodes?
The text was updated successfully, but these errors were encountered: