Repository navigation
Fix incorrect type hint in rich_command.pyi - #319
Conversation
The `get_command` method in `rich_command.py` accepts `click.Context`. However, the stub file `rich_command.pyi` restricts the type to `RichContext`. This mismatch causes static type checkers (like mypy/pyright) to report false positives when a standard `click.Context` is passed, violating the Liskov substitution principle since this method overrides `click.BaseCommand.get_command`. This change relaxes the type hint in the stub to match the implementation and the base class.
There was a problem hiding this comment.
Pull request overview
This pull request fixes a type hint inconsistency between the stub file and the implementation file for the get_command method in RichGroup. The implementation accepts click.Context, but the stub incorrectly restricted it to RichContext, causing false positives in static type checkers.
Changes:
- Updated the type hint for the
ctxparameter inRichGroup.get_command()fromRichContexttoclick.Contextin the stub file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thanks, LGTM. This was a mistaken implementation as we do otherwise maintain contravariance of function signatures. This one slipped through. Good catch. We have some outstanding issues with Liskov substitution because conceptually Click commands should be generically typed (the maintainer agrees). But what you caught was simply an error on my part as for now we just make do. |
The
get_commandmethod inrich_command.pyacceptsclick.Context. However, the stub filerich_command.pyirestricts the type toRichContext.This mismatch causes static type checkers (like mypy/pyright) to report false positives when a standard
click.Contextis passed, violating the Liskov substitution principle since this method overridesclick.BaseCommand.get_command.This change relaxes the type hint in the stub to match the implementation and the base class.