Skip to content

Adding type hints and updating doc on globalconstraints#812

Merged
tias merged 18 commits intomasterfrom
typing_globals
Jan 15, 2026
Merged

Adding type hints and updating doc on globalconstraints#812
tias merged 18 commits intomasterfrom
typing_globals

Conversation

@IgnaceBleukx
Copy link
Copy Markdown
Collaborator

Started going through the global constraints file to update the documentation similar to what was done for the global functions.

  • Adding type hints to the constructor
  • Adding return types for the value/decompose functions
  • Uniform docstring for the class
  • Checking if an argument is None while computing the value

Still work in progress

@IgnaceBleukx IgnaceBleukx marked this pull request as ready for review January 8, 2026 17:23
@IgnaceBleukx
Copy link
Copy Markdown
Collaborator Author

Finished documenting the globalconstraints.py file and updated checks.
Lots of the tests were actually outdated, and do not follow the CPMpy spec... I.e., you are always allowed to use Booleans as integers. Question remains if all of these tests will still work after #780 is merged, I can see some solver interfaces not supporting this currently.

I also removed the call to flatlist in the constructors, it should not be necessary...

Final open point is regarding explicit type checking. E.g., should we check all arguments of a list are indeed the right type? It would be good to do so... but will add some boilerplate code. Although I'm not opposed to it, as all of that checking code is hidden in the constructor anyway, and we have a great friend who can help writing with these checks.

Feedback on doc changes and thoughts on typechecking are welcome : )

@IgnaceBleukx IgnaceBleukx requested a review from tias January 8, 2026 17:27
@tias tias added this to the v.0.10.0 milestone Jan 9, 2026
Copy link
Copy Markdown
Collaborator

@tias tias left a comment

Choose a reason for hiding this comment

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

Great improvement, esp from a documentation point of view.

More precise typing (e.g. Expression can also often be an int or a np.int) to be worked out in subsequent PRs, e.g. #768

@tias tias merged commit 7abfab0 into master Jan 15, 2026
1 check passed
@tias tias deleted the typing_globals branch January 15, 2026 20:16
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