-
Notifications
You must be signed in to change notification settings - Fork 0
Integrate Variant helper from PR #245 for type-specific Python algorithm registration #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,79 @@ | ||||||
| """Annotation helper for C++ typing variants. | ||||||
|
|
||||||
| Python algorithms are generic, like C++ templates, but the Phlex registration | ||||||
| process requires a single unique signature. These helpers generate annotated | ||||||
| functions for registration with the proper C++ types. | ||||||
| """ | ||||||
|
|
||||||
| import copy | ||||||
| from typing import Any, Callable | ||||||
|
|
||||||
|
|
||||||
| class Variant: | ||||||
| """Wrapper to associate custom annotations with a callable. | ||||||
|
|
||||||
| This class wraps a callable and provides custom ``__annotations__`` and | ||||||
| ``__name__`` attributes, allowing the same underlying function or callable | ||||||
| object to be registered multiple times with different type annotations. | ||||||
|
|
||||||
| By default, the provided callable is kept by reference, but can be cloned | ||||||
| (e.g. for callable instances) if requested. | ||||||
|
|
||||||
| Phlex will recognize the "phlex_callable" data member, allowing an unwrap | ||||||
| and thus saving an indirection. To detect performance degradation, the | ||||||
| wrapper is not callable by default. | ||||||
|
|
||||||
| Attributes: | ||||||
| phlex_callable (Callable): The underlying callable (public). | ||||||
| __annotations__ (dict): Type information of arguments and return product. | ||||||
| __name__ (str): The name associated with this variant. | ||||||
|
|
||||||
| Examples: | ||||||
| >>> def add(i: Number, j: Number) -> Number: | ||||||
| ... return i + j | ||||||
| ... | ||||||
| >>> int_adder = variant(add, {"i": int, "j": int, "return": int}, "iadd") | ||||||
|
||||||
| >>> int_adder = variant(add, {"i": int, "j": int, "return": int}, "iadd") | |
| >>> int_adder = Variant(add, {"i": int, "j": int, "return": int}, "iadd") |
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file ends with a trailing blank line (line 80). According to the project's text formatting standards, all text files must have their final line be non-empty and terminated with a single newline character, leaving no trailing blank lines. Remove the blank line at the end of the file.
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new Variant class lacks test coverage. While adder.py demonstrates basic usage, there are no tests verifying:
- That phlex_callable is correctly extracted and used by the framework
- That the call method raises AssertionError when called directly
- That clone functionality (shallow and deep copy) works correctly
- That allow_call parameter works when set to True
Consider adding dedicated test cases for the Variant class to ensure the wrapper behaves correctly in various scenarios.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in docstring: "Typer bound" should be "Type bound".