feat: add TypoMixin for 'Did you mean?' suggestions on invalid commands#255
Open
anandhu-eng wants to merge 1 commit into
Open
feat: add TypoMixin for 'Did you mean?' suggestions on invalid commands#255anandhu-eng wants to merge 1 commit into
anandhu-eng wants to merge 1 commit into
Conversation
When a user mistypes an action (e.g. 'rune') or target (e.g. 'scrip'), the CLI now prints a 'Did you mean ...?' hint between the usage block and the standard argparse error, using difflib.get_close_matches (stdlib, no new dependencies). - mlc/typo_mixin.py: new TypoMixin class that overrides ArgumentParser.error() - mlc/main.py: introduce TypoArgumentParser(TypoMixin, ArgumentParser) and use it in both build_pre_parser() and build_parser(); subparsers inherit the class automatically so target-level typos are also caught - tests/test_typo_mixin.py: 33 tests across unit (suggest()) and CLI subprocess suites covering action typos, target typos, no-match cases, and regression checks on usage/error output - docs/typo_detection.md: full documentation with examples and tuning guide - README.md: mention typo detection in Key Features Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅ |
🤖 AI PR Review Summary\n\nAdds a typo detection feature to the CLI by extending argparse.ArgumentParser with a mixin that suggests close matches for mistyped commands or targets. This improves user experience by providing helpful hints on invalid inputs. The change includes a new TypoMixin class, integration into the main parser, documentation, and tests. Risks are minimal as the mixin only overrides the error method and uses standard library difflib. Design is clean and modular, leveraging Python's MRO and argparse's parser_class inheritance to cover subcommands automatically. |
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.
Summary
mlc/typo_mixin.py— aTypoMixinclass that overridesArgumentParser.error()to print a "Did you mean …?" hint when the user mistypes an action or targetmlc/main.pyviaTypoArgumentParser(TypoMixin, argparse.ArgumentParser); subparsers inherit the class automatically so both action-level and target-level typos are caughtdifflib.get_close_matchesfrom the Python stdlibExample output
Changes
mlc/typo_mixin.pyTypoMixinwithsuggest()anderror()overridemlc/main.pyTypoArgumentParserinbuild_pre_parser()andbuild_parser()tests/test_typo_mixin.pydocs/typo_detection.mdREADME.md.github/workflows/test-unit.ymlTest plan
python -m unittest discover -s tests -p "test_*.py" -v— all 33 tests passrune,pul,fidn,serach,lstscrip,cach,rpoxyzzy123) shows no hint — standard error only🤖 Generated with Claude Code