Skip to content

Fraction wrongfully gets casted into float when given as argument to __rpow__ #119189

Closed
@retooth2

Description

@retooth2

Bug report

Bug description:

When using the ** operator with a Fraction as a base and an object that implements __rpow__ as an exponent the fraction gets wrongfully casted into a float before being passed to __rpow__

from fractions import Fraction

foo = Fraction(4, 3)

class One:
    def __rpow__(self, other):
        return other

bar = foo**One()
print(bar)
print(type(bar))

Expected Output

4/3
<class 'fractions.Fraction'>

Actual Output:

1.3333333333333333
<class 'float'>

Tested with Python 3.12.3

CPython versions tested on:

3.12

Operating systems tested on:

macOS

Linked PRs

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