mypy icon indicating copy to clipboard operation
mypy copied to clipboard

"SupportsInt" doesn't work with Union types

Open sangsta opened this issue 10 years ago • 5 comments

The following shouldn't be an error: error: Argument 1 to "int" has incompatible type "Union[unicode, int]"; expected "SupportsInt"

sangsta avatar Oct 25 '16 21:10 sangsta

In particular, you can repro this for Python 2 with:

from typing import Union
x = 0  # type: Union[int, unicode]
int(x)

ddfisher avatar Oct 25 '16 21:10 ddfisher

I would guess it is another example of #2128 and the general overloading/Union problem.

elazarg avatar Oct 25 '16 22:10 elazarg

FYI this is still an issue in Python 3.6:

error: Argument 1 to "int" has incompatible type "Union[int, str]"; expected "SupportsInt"

nolanlum avatar Feb 09 '18 09:02 nolanlum

Yes, this is an issue in mypy's union deduction checks, and is independent of Python version.

emmatyping avatar Feb 09 '18 09:02 emmatyping

This issue is now fixed (example correctly passes).

ilevkivskyi avatar May 20 '18 06:05 ilevkivskyi