Improve NUMERIC protocol typing with proper variance and missing operators#273
Draft
Improve NUMERIC protocol typing with proper variance and missing operators#273
Conversation
Co-authored-by: williambdean <57733339+williambdean@users.noreply.github.com>
…umber exclusion Co-authored-by: williambdean <57733339+williambdean@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Improve typing for NUMERIC class and resolve linter errors
Improve NUMERIC protocol typing with proper variance and missing operators
Nov 2, 2025
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #273 +/- ##
==========================================
+ Coverage 95.00% 95.03% +0.02%
==========================================
Files 9 9
Lines 1082 1087 +5
==========================================
+ Hits 1028 1033 +5
Misses 54 54 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Owner
|
@copilot this is not passing pre-commit. Please run |
Co-authored-by: williambdean <57733339+williambdean@users.noreply.github.com>
Contributor
Author
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.
Improve typing of the NUMERIC class
Analysis Complete: The
NUMERICProtocol class has several typing issues that can be improved.Issues Identified:
NUMERICinstead ofobject(too restrictive, doesn't match Python's duck typing)__neg__,__pos__,__abs__,__pow__,__floordiv__,__mod__)__lt__,__le__,__gt__,__ge__)@runtime_checkable(best practice for protocols)Selftype for better type inference (requires typing_extensions for Python 3.10+)Changes Made:
1. Enhanced
conjugate/_typing.py:runtime_checkableSelftype: Usestyping.Self(Python 3.11+) with fallback totyping_extensions.Self(Python 3.10)NUMERICtoobjectfor proper contravariance, matching Python's duck typing__floordiv__,__rfloordiv____mod__,__rmod____pow__,__rpow____neg__,__pos__,__abs____lt__,__le__,__gt__,__ge__@runtime_checkabledecorator forisinstance()checks__eq__,__ne__,__hash__: Intentionally excluded to support numpy arrays (which have__hash__ = None)__eq__and__ne__are inherited from object2. Added dependency in
pyproject.toml:typing-extensions>=4.0.0to support Python 3.103. Created comprehensive tests in
tests/test_typing.py://and%)Design Decisions:
__hash__omitted: Allows numpy arrays (unhashable) to conform to the protocolobjectfor parameters: Enables duck typing (e.g.,int + floatworks)Verification:
isinstance()checks work correctlyOriginal prompt
NUMERICclass #96💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.