Skip to content

Can't cast from Fraction to int? #9588

Closed
python/typeshed
#4665
@jvdwetering

Description

@jvdwetering

In mypy 0.770 the following typechecks:

from fractions import Fraction

def f(a: Fraction) -> int:
	return int(a)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions