Skip to content

Use descriptor for stronger typing enforcement#2

Merged
zyrxvo merged 7 commits intomainfrom
stronger-typing
Jan 5, 2026
Merged

Use descriptor for stronger typing enforcement#2
zyrxvo merged 7 commits intomainfrom
stronger-typing

Conversation

@zyrxvo
Copy link
Copy Markdown
Collaborator

@zyrxvo zyrxvo commented Dec 24, 2025

Astral's new type checker ty causes the current implementation of Colour.print to be interpreted as incorrect. This is because a check is made within print to see if self is an instance of Colour or not. If Colour.print is called statically, then self is typically a string and ty panics because self is not an instance of Colour.

This change introduces a descriptor class to manage how print is implemented.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 _PrintDescriptor class to handle dual behavior of the print method
  • Made red_error a 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.

@zyrxvo zyrxvo requested a review from timmysilv December 24, 2025 19:34
@zyrxvo zyrxvo requested a review from timmysilv January 5, 2026 15:45
@zyrxvo zyrxvo merged commit 61c77e9 into main Jan 5, 2026
7 checks passed
@zyrxvo zyrxvo deleted the stronger-typing branch February 11, 2026 22:47
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