Skip to content

Remove unused modulo parameter from Expr.__pow__ and GenExpr.__pow__ - #1269

Closed
Zeroto521 wants to merge 4 commits into
scipopt:masterfrom
Zeroto521:remove-modulo
Closed

Zeroto521 wants to merge 4 commits into
scipopt:masterfrom
Zeroto521:remove-modulo

Conversation

@Zeroto521

@Zeroto521 Zeroto521 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Expr.__pow__ and GenExpr.__pow__ in src/pyscipopt/expr.pxi both declared a third parameter named modulo, but neither method body ever reads it. The effect: pow(x, 2, 5) silently ignores the modulus and returns the un-reduced expression, while Python's own pow convention is that a three-argument call is only meaningful for integers and should raise TypeError when the base does not support it.

Removing the parameter makes the behavior match the convention:

>>> x = Model().addVar()
>>> pow(x, 2, 5)
TypeError: Expr.__pow__() takes 3 arguments but 2 were given

x ** 2 and pow(x, 2) are unchanged.

Expr.__pow__ and GenExpr.__pow__ declared a third parameter
modulo that the method bodies never used, so pow(x, y, mod)
silently ignored the modulus and returned an Expr. Drop the
parameter from both Cython definitions and sync the four affected
mod: Incomplete = ... stubs in scip.pyi. pow(x, y, mod) now
raises TypeError, matching the Python convention that three-arg
pow is only meaningful for integers.
@Zeroto521
Zeroto521 marked this pull request as ready for review October 12, 2026 13:44
Copilot AI balanced review requested due to automatic review settings October 12, 2026 13:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Zeroto521 Zeroto521 changed the title test Remove unused modulo parameter from Expr.__pow__ and GenExpr.__pow__ Oct 12, 2026
@Zeroto521

Zeroto521 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Cython maps __pow__ to the nb_power slot, and the generated wrapper is hardcoded to the three-argument signature (self, value, mod=None, /) — verified via inspect.signature, which is independent of whether the source declares two or three parameters. stubtest compares stubs against the compiled runtime signature, so removing mod from the stub necessarily fails with 'stub does not have parameter mod'.

@Zeroto521 Zeroto521 closed this Oct 12, 2026
@Zeroto521
Zeroto521 deleted the remove-modulo branch October 12, 2026 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants