Skip to content

Preserve decorated CLI command classes - #2524

Open
ktz03 wants to merge 1 commit into
huggingface:mainfrom
ktz03:fix/cli-decorator-preserve-class-1118
Open

ktz03 wants to merge 1 commit into
huggingface:mainfrom
ktz03:fix/cli-decorator-preserve-class-1118

Conversation

@ktz03

@ktz03 ktz03 commented Oct 9, 2026

Copy link
Copy Markdown

What does this PR do?

@optimum_cli_subcommand() registers a command but returns None, replacing the decorated class binding. The registered CLI command still runs, but the class cannot be instantiated, subclassed or reused in a CommandInfo for static registration.

Return the original command class after registration. The two regression cases cover root commands and children of the existing ExportCommand: the decorated class remains usable for static registration and execution, and registration through the actual CLI still works.

Local validation on Windows, Python 3.12:

  • Real public decorator, constructor, subclass, CommandInfo and CLI probe: unchanged main has 7 failures and 5 normal controls; the fix passes all 12 cases.
  • Relevant CLI tests: 4 passed, including both new regressions. Both new regressions fail on unchanged main.
  • Repository-wide Black and Ruff checks passed with the official development versions.

The model-export CLI test was deselected. Full model/export integrations, accelerator backends, other operating systems and performance were not tested.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you make sure to update the documentation with your changes? No documentation update is needed for this bug fix.
  • Did you write any new necessary tests?

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.

1 participant