Skip to content

Typed GenExpr fields - #1281

Open
Zeroto521 wants to merge 5 commits into
scipopt:masterfrom
Zeroto521:typed-expression-fields
Open

Zeroto521 wants to merge 5 commits into
scipopt:masterfrom
Zeroto521:typed-expression-fields

Conversation

@Zeroto521

Copy link
Copy Markdown
Contributor

Expression fields (Constant.number, SumExpr.constant, ProdExpr.constant,
PowExpr.expo, GenExpr.children) were untyped Python attributes that were only converted
to C types when used. This PR gives them concrete Cython types (double/list), so values
are converted once on assignment; the stubs now return float for the numeric fields.

Store GenExpr.children as a C list and the numeric expression fields (Constant.number, SumExpr.constant, ProdExpr.constant, PowExpr.expo) as C doubles. Update the stub return types accordingly and note the conversion-on-construction in the changelog.
PowExpr.expo is now stored as a double, so the exponent is rendered as e.g. -1.0 instead of -1.
Comment thread src/pyscipopt/expr.pxi Outdated
Comment thread src/pyscipopt/scip.pyi
class Constant(GenExpr):
@property
def number(self) -> SupportsFloat: ...
def number(self) -> float: ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

numebr is float now, not like float. SupportsFloat uses the __float__ protocol.

@Zeroto521
Zeroto521 marked this pull request as ready for review October 28, 2026 15:18
Copilot AI balanced review requested due to automatic review settings October 28, 2026 15:18

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 insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@Joao-Dionisio

Copy link
Copy Markdown
Member

Hey @Zeroto521 , are there no more changes of this type that you have planned? If there are, please apply them all here.

The concrete Cython field types make Decimal operands work at runtime, so
the generator now emits additional assert_type checks that mypy reports.

This branch has not been deployed

No deployments
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.

3 participants