You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Wrong overload resolution with Any union item in argument #5249
I think we should switch to a new union math algorithm, I have some ideas how to make it fast enough to replace the current one (that is apparently to dangerous). I will give it a try now.
List[int] is inconsistent with how Any works with overloads generally -- if there is ambiguity due to Any types in overload resolution, we tend to fall back to Any to avoid false positives. False negatives are preferred over false positives when Any types are involved. Here is a simple analogy:
We don't infer Union[str, int] as the type of a.x even though int is a plausible type for a.x -- since it could well be something else. Similarly, the precise type of i could actually be just int (though we can't tell for certain), and assuming that it can be a slice would be wrong.
Activity
ilevkivskyi commentedon Jun 20, 2018
I think we should switch to a new union math algorithm, I have some ideas how to make it fast enough to replace the current one (that is apparently to dangerous). I will give it a try now.
JukkaL commentedon Jun 20, 2018
Another real-world example where things go wrong:
JelleZijlstra commentedon Jun 20, 2018
I think that one is actually correct: if
iis a slice object, it will returnList[int].JukkaL commentedon Jun 20, 2018
List[int]is inconsistent with howAnyworks with overloads generally -- if there is ambiguity due toAnytypes in overload resolution, we tend to fall back toAnyto avoid false positives. False negatives are preferred over false positives whenAnytypes are involved. Here is a simple analogy:We don't infer
Union[str, int]as the type ofa.xeven thoughintis a plausible type fora.x-- since it could well be something else. Similarly, the precise type oficould actually be justint(though we can't tell for certain), and assuming that it can be a slice would be wrong.ilevkivskyi commentedon Jun 21, 2018
The PR I am working on will produce (after some tweaks that I didn't push yet)
Union[int, Any]for this example:@JukkaL does this make sense to you?
ilevkivskyi commentedon Jun 21, 2018
(Also I think
Union[D, Any]in the original example is best.)JukkaL commentedon Jun 21, 2018
Yes, I think that
Union[int, Any]is the most correct type fora[i], and similarlyUnion[D, Any]for the other example.Alternative algorithm for union math (#5255)