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
Cannot inference common base class when root of hierarchy is Any #5134
This looks like another case where the conditional expression should take the context into account. I wonder if it works as expected when #5095 is reverted?
OK, then the fix would entail improving on that diff (it partially reverted #5041, which would have the desired effect here but not in general). Perhaps we should always try the make_simplified_union() call and accept the return value if it's not a Union -- that seems to be the case here.
TBH, I would also allow Optional[...] as a result of make_simplified_union, so that the rules would be:
in union context, always use union
otherwise, use make_simplified_union if the result is a non-union, or a union of two types one of which is None
otherwise fallback to join
The point is that Any can "swallow" None, so that unimported if x else None results in just Any, not Optional[Any] (this however reveals few dozens of real errors in our internal codebases).
Activity
asottile commentedon Jun 1, 2018
Note that this also passes (why I believe to be ~related to
Anyhere):gvanrossum commentedon Jun 1, 2018
This looks like another case where the conditional expression should take the context into account. I wonder if it works as expected when #5095 is reverted?
asottile commentedon Jun 1, 2018
Seems to work as expected when reverting that, yes:
gvanrossum commentedon Jun 1, 2018
OK, then the fix would entail improving on that diff (it partially reverted #5041, which would have the desired effect here but not in general). Perhaps we should always try the make_simplified_union() call and accept the return value if it's not a Union -- that seems to be the case here.
ilevkivskyi commentedon Jun 1, 2018
TBH, I would also allow
Optional[...]as a result ofmake_simplified_union, so that the rules would be:make_simplified_unionif the result is a non-union, or a union of two types one of which isNoneThe point is that
Anycan "swallow"None, so thatunimported if x else Noneresults in justAny, notOptional[Any](this however reveals few dozens of real errors in our internal codebases).hauntsaninja commentedon Aug 13, 2023
I fixed this in #14404