Annotate arithmetic operations#1231
Conversation
| - name: Install Ruff | ||
| uses: astral-sh/ruff-action@v3 | ||
| with: | ||
| version: "0.14.11" |
There was a problem hiding this comment.
I removed the pin because this version was causing a weird formatting that was fixed in recent versions, but feel free to pin to a higher version if you want to keep a pinned version @Joao-Dionisio
|
Hey @jonathanberthias , thank you, great job on greatly reducing the number of errors! Here's what my Claude flagged: 1.
|
|
By the way, @jonathanberthias , apologies if I've already asked this, but what are you using SCIP for, out of curiosity? 😄 |
|
Thanks for the review, all good findings!
At my previous job, I was using it for portfolio optimization with many integer constraints as an alternative to Gurobi, and I was very impressed with the quality of the results! I don't use it that much anymore though, it's just a side-project 😄 |
As a follow up to #1229, we can now quickly evaluate the effect of annotating all the arithmetic operations.
This PR adds annotations to the stubs for nearly all the simple cases. There are still some areas where the annotations are not correct, and they fall broadly in the following categories:
np.ndarraymethods: we are changing the return values of the operations compared to the base class, which in the best case works with atype: ignore[override]comment, and in the worst case makes it impossible to get the type checker to infer the correct resultMatrixExprreturns aMatrixExprin general, except if both are 1D in which case the result is anExpr. Likewise, operations with 0D-MatrixExprfail to type-check correctly. This kind of "shape-typing" is possible to do I believe, but is more complex than I reached for in this PRDecimal: I annotated things withfloatto keep them simple, but that is actually too restrictive. Semanticallytyping.SupportsFloatis correct, but that also matchesnp.ndarraywhich makes many operations fail to type-check. This is an open issue to be solvedTerm: somehow many operations with aTermobject succeed at runtime, but that seems wrong to mePart of #1072