Skip to content

Fraction(float) doesn't behave like Fraction(float, 1) #149424

@retooth2

Description

@retooth2

Bug report

Bug description:

Hi, I discovered the following bug in the init of the Fraction object:

from fractions import Fraction

print(Fraction(0.5) == Fraction(0.5, 1))

Expected Output:

True

Actual Output:

*** TypeError: both arguments should be Rational instances

Similarly:

from fractions import Fraction

print(Fraction(0.5, 0.5) == Fraction(1))

Expected Output:

True

Actual Output:

*** TypeError: both arguments should be Rational instances

Tested on

Python 3.11.7
Python 3.13.4

CPython versions tested on:

3.11, 3.13

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions