KEMBAR78
Improve pow(fraction.Fraction(), b, modulo) error message · Issue #119594 · python/cpython · GitHub
Skip to content

Improve pow(fraction.Fraction(), b, modulo) error message #119594

@wimglenn

Description

@wimglenn

Bug report

Bug description:

Fraction.__pow__ does not accept the third argument which pow tries to pass to it:

>>> pow(Fraction(1), 1, 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Fraction.__pow__() takes 2 positional arguments but 3 were given

Other number types don't do that, they support it when they can and print an error message if they don't want to, e.g.

>>> pow(Decimal("1"), 1, 1)
Decimal('0')
>>> pow(Decimal('1'), 1.1, 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: pow() 3rd argument not allowed unless all arguments are integers

I'm not sure what fraction should do, maybe it should just continue not to support it? Or just accept the argument, and then print a better error message if modulo is not None?

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions