Skip to content

Issues with Decimal and three-argument pow() #130230

Closed
@serhiy-storchaka

Description

@serhiy-storchaka

Crash report

  1. Three-argument pow() with non-Decimal first argument does not work in the Python implementation.
>>> from decimal import Decimal
>>> pow(10, Decimal(2), 7)
Decimal('2')
>>> from _pydecimal import Decimal
>>> pow(10, Decimal(2), 7)
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    pow(10, Decimal(2), 7)
    ~~~^^^^^^^^^^^^^^^^^^^
TypeError: unsupported operand type(s) for ** or pow(): 'int', 'Decimal', 'int'

But it works in the C implementation.

  1. Three-argument pow() with only Decimal third argument crashes in the C implementation.
>>> from decimal import Decimal
>>> pow(10, 2, Decimal(7))
python: ./Modules/_decimal/_decimal.c:139: find_state_left_or_right: Assertion `mod != NULL' failed.
Aborted (core dumped)

In the Python implementation it only raises TypeError, which is expected.

Linked PRs

Metadata

Metadata

Labels

3.13bugs and security fixes3.14bugs and security fixesextension-modulesC modules in the Modules dirstdlibPython modules in the Lib dirtype-crashA hard crash of the interpreter, possibly with a core dump

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions