-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Can't cast from Fraction to int? #9588
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
Comments
This fails for me with 0.770 as well. I assume this is similar to #3186 |
My bad, I accidentally had it ignoring the error in my 0.770 installation. But similar code I had in a more complicated code base did parse with 0.770, but started to raise errors when I upgraded mypy to 0.790 (even though I did not change anything about the codebase). And yeah, this definitely looks to be related to #3186. |
Regressions are typically easier to fix, so if you find the failure that would be useful. Could be a problem in python/typeshed#4401 if that made it into the release |
Okay, I found a variant of my code above that does work in 0.770 but not in 0.790:
Removing the |
Thanks! Okay, this is triggered by python/typeshed#4401 (but isn't a bug). That PR adds a return type for Fraction's |
That makes sense. So now the remaining problem is that int() should really know how to deal with a Fraction, right? |
Yeah. From a glance, I'm not actually sure how this is even accomplished in CPython since Fraction doesn't have |
Here you go, this should fix things: python/typeshed#4665 |
Refer to https://docs.python.org/3/reference/datamodel.html#object.__trunc__ Fixes python/mypy#9588 Co-authored-by: hauntsaninja <>
Otherwise it fails with: src/aiortc/mediastreams.py:22: error: No overload variant of "int" matches argument type "Fraction" src/aiortc/mediastreams.py:22: note: Possible overload variant: src/aiortc/mediastreams.py:22: note: def __init__(self, x: Union[str, bytes, SupportsInt, _SupportsIndex] = ...) -> int src/aiortc/mediastreams.py:22: note: <1 more non-matching overload not shown> See: python/mypy#9588
Otherwise it fails with: src/aiortc/mediastreams.py:22: error: No overload variant of "int" matches argument type "Fraction" src/aiortc/mediastreams.py:22: note: Possible overload variant: src/aiortc/mediastreams.py:22: note: def __init__(self, x: Union[str, bytes, SupportsInt, _SupportsIndex] = ...) -> int src/aiortc/mediastreams.py:22: note: <1 more non-matching overload not shown> See: python/mypy#9588
Otherwise it fails with: src/aiortc/mediastreams.py:22: error: No overload variant of "int" matches argument type "Fraction" src/aiortc/mediastreams.py:22: note: Possible overload variant: src/aiortc/mediastreams.py:22: note: def __init__(self, x: Union[str, bytes, SupportsInt, _SupportsIndex] = ...) -> int src/aiortc/mediastreams.py:22: note: <1 more non-matching overload not shown> See: python/mypy#9588
Otherwise it fails with: src/aiortc/mediastreams.py:22: error: No overload variant of "int" matches argument type "Fraction" src/aiortc/mediastreams.py:22: note: Possible overload variant: src/aiortc/mediastreams.py:22: note: def __init__(self, x: Union[str, bytes, SupportsInt, _SupportsIndex] = ...) -> int src/aiortc/mediastreams.py:22: note: <1 more non-matching overload not shown> See: python/mypy#9588
Otherwise it fails with: src/aiortc/mediastreams.py:22: error: No overload variant of "int" matches argument type "Fraction" src/aiortc/mediastreams.py:22: note: Possible overload variant: src/aiortc/mediastreams.py:22: note: def __init__(self, x: Union[str, bytes, SupportsInt, _SupportsIndex] = ...) -> int src/aiortc/mediastreams.py:22: note: <1 more non-matching overload not shown> See: python/mypy#9588
Otherwise it fails with: src/aiortc/mediastreams.py:22: error: No overload variant of "int" matches argument type "Fraction" src/aiortc/mediastreams.py:22: note: Possible overload variant: src/aiortc/mediastreams.py:22: note: def __init__(self, x: Union[str, bytes, SupportsInt, _SupportsIndex] = ...) -> int src/aiortc/mediastreams.py:22: note: <1 more non-matching overload not shown> See: python/mypy#9588
Otherwise it fails with: src/aiortc/mediastreams.py:22: error: No overload variant of "int" matches argument type "Fraction" src/aiortc/mediastreams.py:22: note: Possible overload variant: src/aiortc/mediastreams.py:22: note: def __init__(self, x: Union[str, bytes, SupportsInt, _SupportsIndex] = ...) -> int src/aiortc/mediastreams.py:22: note: <1 more non-matching overload not shown> See: python/mypy#9588
In mypy 0.770 the following typechecks:
But it raises the following error in mypy 0.790: "error: No overload variant of "int" matches argument type "Fraction""
If I replace the last line with
return int(float(a))
, it does typecheck.Is this intended behaviour?
EDIT: The code above actually also doesn't compile on 0.770, see below on modified code that does work on 0.770 but gives an error on 0.790
The text was updated successfully, but these errors were encountered: