Skip to content

Fix three-argument pow() raising ValueError for operands complex cannot convert - #1353

Open
jseop-lim wants to merge 1 commit into
oracle:masterfrom
jseop-lim:fix/complex-pow-modulo-operands
Open

jseop-lim wants to merge 1 commit into
oracle:masterfrom
jseop-lim:fix/complex-pow-modulo-operands

Conversation

@jseop-lim

Copy link
Copy Markdown
Contributor

Description

Part of #1291 (item 8).

PowerNode.error raises ValueError: complex modulo for any call with a modulus, before the operands are converted. CPython's complex_pow converts both operands first and returns NotImplemented when one cannot be converted.

AS-IS

>>> pow(1, int, 1j)
ValueError: complex modulo
>>> pow(1j, set(), 3)
ValueError: complex modulo

TO-BE

>>> pow(1, int, 1j)
TypeError: unsupported operand type(s) for ** or pow(): 'int', 'type', 'complex'
>>> pow(1j, set(), 3)
TypeError: unsupported operand type(s) for ** or pow(): 'complex', 'set', 'int'

(matching CPython)

Changes

  • In error, convert both operands with ToComplexValueNode and return NotImplemented when either fails, before raising for the modulus.
  • Add a test to tests/test_complex.py.

Testing

mx python-jvm on darwin-aarch64, then mx graalpytest on test_complex.py (the new test fails on the unpatched build and passes with the fix) and the tagged test_complex (35 passed). mx python-checkcopyrights, mx eclipseformat and mx checkstyle are clean.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant