Skip to content

Modernize __init__ files#905

Open
IgnaceBleukx wants to merge 9 commits intomasterfrom
ruff-init
Open

Modernize __init__ files#905
IgnaceBleukx wants to merge 9 commits intomasterfrom
ruff-init

Conversation

@IgnaceBleukx
Copy link
Copy Markdown
Collaborator

Reformat the init files and properly enforce what is "exported" from the package using the __all__ tags.
It allows IDE's to properly inspect what is available from the package

The formatting of imports was unnatural to me at first, but it actually makes a lot of sense. Also massively simplifies merges when two branches add a global constraint for example...

@IgnaceBleukx IgnaceBleukx marked this pull request as draft April 3, 2026 16:30
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.

yes, all good for me, also appropriate to add the ruff formatting at the same time.

One thing I wonder, now we import all constraints as part of cpmpy.expression.init
and then cpmpy.init still has a *

would an alternative be to only import them in cpmpy.init, and have the other packages not load anything else in there init? or is this the current way the right way (but for example SolverLookup is directly imported from top init, not in cpmpy.solvers; or is that an oversight, or maybe on purpose because it is not a solver? or maybe because those solvers in cpmpy.solvers.init are not exported in the top one as well...

we want all those you have now in the top in any case...

@IgnaceBleukx
Copy link
Copy Markdown
Collaborator Author

I've added a test to ensure we import all of the global constraints at the cpmpy.expressions level now (otherwise we will probably forget when adding future globals...)

Importing everything at the __init__ level could also work, I can't really find guidelines on best practices for this...
I' ve now changed the init of .solvers to also export SolverLookup. There is no real reason for not doing it imho

@IgnaceBleukx IgnaceBleukx marked this pull request as ready for review April 6, 2026 19:15
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