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
Unexpected type 'unicode' for os.path.join() with (Any, str) args #5232
The revealed type for the os.path.join call in the program below is unicode, even though I'd expect either Any or str, as the arguments have types Any and str:
@Michael0x2a Do you have time to have a look at this? This is causing issues in internal Dropbox repos. If you are busy, I can try to fix this. This was apparently introduced by f61c2ba.
I think the issue is that due to the way we handle promotions in mypy, bytes is actually technically considered to be a subtype of unicode -- so the union math logic concludes that it's valid to return unicode instead of Any since the former is more precise.
Not sure what the best way to handle this is -- I'd personally prefer just removing that promotion altogether, but that's a very invasive and difficult-to-implement change. Alternatively, we could special-case this in the union math somehow, but that would make it inconsistent with the rest of mypy. E.g. this currently typechecks, for example:
My original motivation for requesting it was that this example should work
@overloaddeff(x: List[int]) ->List[int]: ...
@overloaddeff(x: List[Any]) ->List[Any]: ...
arg: Anyf(arg) # should be List[Any], _not_ just Any
Also now I think that we should really check both ways, because the logic is that replacing a precise type with Any should ideally not cause new errors. For example:
deff() ->int: ...
@overloaddefg(x: int) ->int: ...
@overloaddefg(x: float) ->float: ...
x: int=g(f()) # this passes, but will fail if I remove the annotation from 'f'
I will now prepare a PR to return last type only if it is compatible both ways with all other return types (like in the first example with List[Any]).
Activity
ilevkivskyi commentedon Jun 18, 2018
I am looking at this now.
Michael0x2a commentedon Jun 18, 2018
I think the issue is that due to the way we handle promotions in mypy,
bytesis actually technically considered to be a subtype ofunicode-- so the union math logic concludes that it's valid to returnunicodeinstead ofAnysince the former is more precise.Not sure what the best way to handle this is -- I'd personally prefer just removing that promotion altogether, but that's a very invasive and difficult-to-implement change. Alternatively, we could special-case this in the union math somehow, but that would make it inconsistent with the rest of mypy. E.g. this currently typechecks, for example:
Michael0x2a commentedon Jun 18, 2018
I guess other options include:
ilevkivskyi commentedon Jun 18, 2018
My original motivation for requesting it was that this example should work
Also now I think that we should really check both ways, because the logic is that replacing a precise type with
Anyshould ideally not cause new errors. For example:I will now prepare a PR to return last type only if it is compatible both ways with all other return types (like in the first example with
List[Any]).Fix overload interaction with Any (#5233)