Skip to content

Fix incorrect type hint in rich_command.pyi - #319

Merged
dwreeves merged 1 commit into
ewels:mainfrom
nemowang2003:fix-pyi
Jan 14, 2026
Merged

dwreeves merged 1 commit into
ewels:mainfrom
nemowang2003:fix-pyi

Conversation

@nemowang2003

Copy link
Copy Markdown
Contributor

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.

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.
Copilot AI review requested due to automatic review settings January 14, 2026 03:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ctx parameter in RichGroup.get_command() from RichContext to click.Context in the stub file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dwreeves

dwreeves commented Jan 14, 2026 •

Copy link
Copy Markdown
Collaborator

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.

@dwreeves
dwreeves merged commit cf09124 into ewels:main Jan 14, 2026
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.

3 participants