fix(cli): default unset optional flags to InferenceSettings values#233
Open
mountarreat wants to merge 1 commit intonikopueringer:mainfrom
Open
fix(cli): default unset optional flags to InferenceSettings values#233mountarreat wants to merge 1 commit intonikopueringer:mainfrom
mountarreat wants to merge 1 commit intonikopueringer:mainfrom
Conversation
The headless branch of `run-inference` (`corridorkey_cli.py:369-379`)
constructs `InferenceSettings(...)` directly when the four required
flags (--linear/--srgb, --despill, --despeckle, --refiner) are all
provided. Four optional flags (--comp, --gpu-post, --image-size,
--tile) were forwarded as-is, so a `None` from Typer's default flowed
straight into dataclass fields typed `bool` or `int`.
Running the new regression test (committed in the same change)
against unfixed code confirmed the resulting settings object as:
InferenceSettings(..., generate_comp=None,
gpu_post_processing=None, image_size=None,
tiled_inference=None)
which silently breaks downstream code that treats these fields as
bool/int. The interactive branch (`_prompt_inference_settings` at
lines 161-164) already handled this correctly by falling back to
`InferenceSettings.<field>` when a default is None.
Apply the same pattern to the headless branch: for each of the four
optional flags, fall back to the class-level dataclass default when
the CLI-provided value is None. The class-attribute access is
preferred over hardcoded defaults because it tracks any future
change to the dataclass automatically.
Add `test_headless_optional_flags_use_dataclass_defaults` in the
existing `TestNonInteractiveFlags` class; it invokes the CLI with
only the four required flags and asserts the four optional fields
inherit their dataclass defaults (True, False, 2048, False).
Verified locally on Windows with Python 3.13.11:
- uv run ruff format --check: clean
- uv run ruff check: clean
- New test fails on upstream/main without the fix, passes with it.
- uv run pytest -q --tb=short -m "not gpu": 364 passed, 1 skipped
(MLX), 4 deselected (GPU), 2 warnings. The +1 pass vs upstream's
363 is the new regression test. Both warnings are pre-existing on
upstream/main: the unknown-option `env` warning (addressed on a
separate branch) and a torch autocast warning on a no-CUDA
machine. Neither is introduced by this change.
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.
What does this change?
The headless branch of
run-inference(
corridorkey_cli.py:369-379) constructsInferenceSettings(...)directly when the four required flags (
--linear/--srgb,--despill,--despeckle,--refiner) are all provided. Fouroptional flags (
--comp,--gpu-post,--image-size,--tile)were forwarded as-is, so a
Nonefrom Typer's default flowedstraight into dataclass fields typed
boolorint.Running the new regression test against unfixed code confirmed the
resulting settings object as:
which silently breaks downstream code treating those fields as
bool/int. The interactive branch(
_prompt_inference_settings, lines 161-164) already handled thisby falling back to
InferenceSettings.<field>when a default wasNone.This PR applies the same pattern to the headless branch and adds
test_headless_optional_flags_use_dataclass_defaultsin theexisting
TestNonInteractiveFlagsclass to prevent regression.How was it tested?
TDD: wrote the regression test first, observed it fail against the
bug on
upstream/main, applied the fix, observed the test pass.Then full-suite regression check.
uv run ruff format --check: cleanuv run ruff check: cleanuv run pytest -q --tb=short -m "not gpu": 364 passed, 1 skipped(MLX), 4 deselected (GPU). The +1 pass vs upstream's 363 is the
new regression test.
PytestConfigWarning: Unknown config option: envand a torch autocast warning on ano-CUDA machine) are both pre-existing on
upstream/mainand notintroduced by this change.
uv run corridorkey --help: exits 0Checklist
uv run pytestpassesuv run ruff checkpassesuv run ruff format --checkpasses