Use descriptor for stronger typing enforcement#2
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a descriptor-based implementation for the Colour.print method to resolve type checking issues with Astral's new type checker ty. The descriptor pattern allows the print method to behave differently when accessed from the class versus an instance, providing stronger type enforcement.
Key changes:
- Introduced
_PrintDescriptorclass to handle dual behavior of the print method - Made
red_errora proper static method - Updated version from 0.1.0 to 0.1.1 across configuration files
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| colours/main.py | Implements the descriptor pattern for print method; updates __call__ parameter name and type; properly decorates red_error as static |
| tests/tests.py | Adds test case for calling red_error from an instance to verify static method behavior |
| pyproject.toml | Bumps version to 0.1.1 and adds ANN401 to ruff ignore list |
| uv.lock | Updates version to 0.1.1 |
| .pre-commit-config.yaml | Adds ty type checker as a local pre-commit hook |
| .github/workflows/version-check.yaml | Adds new workflow to enforce version bumps on PRs |
| .github/workflows/tests.yaml | Updates uv version from 0.9.10 to 0.9.18 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
timmysilv
reviewed
Dec 29, 2025
timmysilv
approved these changes
Jan 5, 2026
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.
Astral's new type checker
tycauses the current implementation ofColour.printto be interpreted as incorrect. This is because a check is made withinprintto see ifselfis an instance ofColouror not. IfColour.printis called statically, thenselfis typically a string andtypanics becauseselfis not an instance ofColour.This change introduces a descriptor class to manage how
printis implemented.