Fix implicit Optional annotations - #3529
Open
VenishPaneliya wants to merge 2 commits into
Open
VenishPaneliya wants to merge 2 commits into
VenishPaneliya wants to merge 2 commits into
Conversation
Four parameters annotate a concrete type but default to None, which PEP 484 prohibits: - Problem._solve takes `solver: str = None`; the body branches on `if solver is not None:` to decide whether to auto-select. - GLOP, PDLP and SCIP's solve_via_data take `solver_cache: dict = None`. The other 43 solver interfaces leave the same parameter unannotated as `solver_cache=None`, and the codebase checks `solver_cache is not None`, so only these three introduced an annotation that excludes the None they default to. Used `| None` to match the codebase, which uses it throughout and has no `Optional[`. Annotation-only, no behaviour change.
Collaborator
|
Requested in review: the four annotation fixes in this PR bring the package into compliance with ruff's RUF013, so enable the rule rather than leaving it as a one-off cleanup. It complements UP007, which is already enabled. 'ruff check .' passes across the repo with it on.
Author
|
Thanks — done on point 2. I've enabled the rule in "RUF013", # Implicit Optional: PEP 484 prohibits `x: int = None`It sits naturally alongside On point 1, the CLA: this one needs a browser sign-in on cla-assistant, which is on me to complete rather than something I can do from the PR. I'll get it signed and re-trigger the check. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Four parameters annotate a concrete type but default to
None, which PEP 484 prohibits. In each caseNoneis a real, intended value, so only the annotation is wrong — annotation-only, no behaviour change.ruff's rule for this fires onmasterand is clean afterwards:Problem._solve(solver: str = None)— the body branches onif solver is not None:to decide whether to auto-select a solver, soNoneis the intended "not specified" value.solve_via_data(solver_cache: dict = None)in GLOP, PDLP and SCIP — this one is a consistency outlier. Across the solver interfaces the same parameter appears 43 times as a plain, unannotatedsolver_cache=None, and elsewhere the code checkssolver_cache is not None. Only these three added adictannotation, and it excludes theNonethey default to.I used
| Noneto match the codebase (225 uses of| None, none ofOptional[). Three of the four files don't havefrom __future__ import annotations, but withrequires-python = ">=3.11",dict | Noneevaluates fine at runtime — I checked.Issue link (if applicable): n/a
Type of change
Contribution checklist
ruff checkclean on all four filesOn tests: I couldn't run the suite locally — importing cvxpy from source needs the compiled extensions (it fails on
qdldlin my environment). Since this only touches annotations, I verified the four modules compile and that the new annotations evaluate at runtime, and I'm relying on CI for the rest.