Skip to content

Commit dda9cb9

Browse files
Rename AdjustAnnotations to Variant
This commit renames the `AdjustAnnotations` class to `Variant` in both Python and C++ source files, as well as in tests and build configurations. All references to the old name have been removed, and related files have been renamed for consistency. - Renamed `AdjustAnnotations` to `Variant` in `plugins/python/python/phlex/__init__.py` - Renamed C++ class `AdjustAnnotations` to `Variant` in `plugins/python/src/modulewrap.cpp` - Updated `test/python/adder.py` to use `Variant` - Renamed `test/python/unit_test_annotations.py` to `test/python/unit_test_variant.py` - Renamed `test/python/pymismatch_annotations.jsonnet` to `test/python/pymismatch_variant.jsonnet` - Updated `test/python/CMakeLists.txt` to reflect the name and file changes. Co-authored-by: greenc-FNAL <2372949+greenc-FNAL@users.noreply.github.com>
1 parent 4a3ef67 commit dda9cb9

File tree

6 files changed

+29
-29
lines changed

6 files changed

+29
-29
lines changed

plugins/python/python/phlex/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from typing import Any, Callable
88

99

10-
class AdjustAnnotations:
10+
class Variant:
1111
"""Wrapper to associate custom annotations with a callable.
1212
1313
This class wraps a callable and provides custom ``__annotations__`` and
@@ -30,7 +30,7 @@ class AdjustAnnotations:
3030
>>> def add(i: Number, j: Number) -> Number:
3131
... return i + j
3232
...
33-
>>> int_adder = AdjustAnnotations(add, {"i": int, "j": int, "return": int}, "iadd")
33+
>>> int_adder = Variant(add, {"i": int, "j": int, "return": int}, "iadd")
3434
"""
3535

3636
def __init__(
@@ -70,14 +70,14 @@ def __init__(
7070
def __call__(self, *args, **kwargs):
7171
"""Raises an error if called directly.
7272
73-
AdjustAnnotations instances should not be called directly. The framework should
73+
Variant instances should not be called directly. The framework should
7474
extract ``phlex_callable`` instead and call that.
7575
7676
Raises:
7777
AssertionError: To indicate incorrect usage, unless overridden.
7878
"""
7979
assert self._allow_call, (
80-
f"AdjustAnnotations '{self.__name__}' was called directly. "
80+
f"Variant '{self.__name__}' was called directly. "
8181
f"The framework should extract phlex_callable instead."
8282
)
8383
return self.phlex_callable(*args, **kwargs) # type: ignore

plugins/python/src/modulewrap.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -670,12 +670,12 @@ namespace {
670670
// back to dictionary iteration only if introspection fails.
671671
//
672672
// This logic mirrors the Python test class variant.py originally from PR #245.
673-
class AdjustAnnotations {
673+
class Variant {
674674
PyObject* m_callable;
675675
PyObject* m_annotations;
676676

677677
public:
678-
AdjustAnnotations(PyObject* callable) : m_callable(callable), m_annotations(nullptr)
678+
Variant(PyObject* callable) : m_callable(callable), m_annotations(nullptr)
679679
{
680680
PyObject* name = PyUnicode_FromString("__annotations__");
681681
m_annotations = PyObject_GetAttr(m_callable, name);
@@ -691,7 +691,7 @@ class AdjustAnnotations {
691691
Py_DECREF(name);
692692
}
693693

694-
~AdjustAnnotations() { Py_XDECREF(m_annotations); }
694+
~Variant() { Py_XDECREF(m_annotations); }
695695

696696
void get_input_types(std::vector<std::string>& types)
697697
{
@@ -830,7 +830,7 @@ static PyObject* parse_args(PyObject* args,
830830
// retrieve C++ (matching) types from annotations
831831
input_types.reserve(input_labels.size());
832832

833-
AdjustAnnotations adj(callable);
833+
Variant adj(callable);
834834
adj.get_return_type(output_types);
835835
adj.get_input_types(input_types);
836836

test/python/CMakeLists.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ if(HAS_CPPYY)
6868
set(PYTHON_TEST_PHLEX_INSTALL ${CMAKE_SOURCE_DIR})
6969
endif()
7070

71-
set(PYTHON_TEST_FILES test_phlex.py unit_test_annotations.py)
71+
set(PYTHON_TEST_FILES test_phlex.py unit_test_variant.py)
7272

7373
# Determine pytest command based on coverage support
7474
if(HAS_PYTEST_COV AND ENABLE_COVERAGE)
@@ -156,15 +156,15 @@ if(HAS_NUMPY)
156156
list(APPEND ACTIVE_PY_CPHLEX_TESTS py:baduint)
157157

158158
add_test(
159-
NAME py:mismatch_ann
160-
COMMAND phlex -c ${CMAKE_CURRENT_SOURCE_DIR}/pymismatch_annotations.jsonnet
159+
NAME py:mismatch_variant
160+
COMMAND phlex -c ${CMAKE_CURRENT_SOURCE_DIR}/pymismatch_variant.jsonnet
161161
)
162162
set_tests_properties(
163-
py:mismatch_ann
163+
py:mismatch_variant
164164
PROPERTIES
165165
PASS_REGULAR_EXPRESSION "number of inputs .* does not match number of annotation types"
166166
)
167-
list(APPEND ACTIVE_PY_CPHLEX_TESTS py:mismatch_ann)
167+
list(APPEND ACTIVE_PY_CPHLEX_TESTS py:mismatch_variant)
168168

169169
add_test(NAME py:veclists COMMAND phlex -c ${CMAKE_CURRENT_SOURCE_DIR}/pyveclists.jsonnet)
170170
list(APPEND ACTIVE_PY_CPHLEX_TESTS py:veclists)
@@ -256,7 +256,7 @@ set_tests_properties(
256256

257257
# Unit tests for the phlex python package
258258
add_test(
259-
NAME py:unit_annotations
260-
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/unit_test_annotations.py
259+
NAME py:unit_variant
260+
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/unit_test_variant.py
261261
)
262-
set_tests_properties(py:unit_annotations PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}")
262+
set_tests_properties(py:unit_variant PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}")

test/python/adder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from typing import Protocol, TypeVar
88

9-
from phlex import AdjustAnnotations
9+
from phlex import Variant
1010

1111

1212
class AddableProtocol[T](Protocol):
@@ -54,5 +54,5 @@ def PHLEX_REGISTER_ALGORITHMS(m, config):
5454
Returns:
5555
None
5656
"""
57-
int_adder = AdjustAnnotations(add, {"i": int, "j": int, "return": int}, "iadd")
57+
int_adder = Variant(add, {"i": int, "j": int, "return": int}, "iadd")
5858
m.transform(int_adder, input_family=config["input"], output_products=config["output"])
File renamed without changes.
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
#!/usr/bin/env python3
2-
"""Unit tests for the phlex.AdjustAnnotations class."""
2+
"""Unit tests for the phlex.Variant class."""
33

44
import unittest
55

6-
from phlex import AdjustAnnotations
6+
from phlex import Variant
77

88

99
def example_func(a, b=1):
1010
"""Example function for testing."""
1111
return a + b
1212

1313

14-
class TestAdjustAnnotations(unittest.TestCase):
15-
"""Tests for AdjustAnnotations wrapper."""
14+
class TestVariant(unittest.TestCase):
15+
"""Tests for Variant wrapper."""
1616

1717
def test_initialization(self):
1818
"""Test proper initialization and attribute exposure."""
1919
ann = {"a": int, "b": int, "return": int}
20-
wrapper = AdjustAnnotations(example_func, ann, "example_wrapper")
20+
wrapper = Variant(example_func, ann, "example_wrapper")
2121

2222
self.assertEqual(wrapper.__name__, "example_wrapper")
2323
self.assertEqual(wrapper.__annotations__, ann)
@@ -28,21 +28,21 @@ def test_initialization(self):
2828

2929
def test_call_by_default_raises(self):
3030
"""Test that calling the wrapper raises AssertionError by default."""
31-
wrapper = AdjustAnnotations(example_func, {}, "no_call")
31+
wrapper = Variant(example_func, {}, "no_call")
3232
with self.assertRaises(AssertionError) as cm:
3333
wrapper(1)
3434
self.assertIn("was called directly", str(cm.exception))
3535

3636
def test_allow_call(self):
3737
"""Test that calling is allowed when configured."""
38-
wrapper = AdjustAnnotations(example_func, {}, "yes_call", allow_call=True)
38+
wrapper = Variant(example_func, {}, "yes_call", allow_call=True)
3939
self.assertEqual(wrapper(10, 20), 30)
4040

4141
def test_clone_shallow(self):
4242
"""Test shallow cloning behavior."""
4343
# For a function, copy.copy just returns the function itself usually,
44-
# but let's test the flag logic in AdjustAnnotations
45-
wrapper = AdjustAnnotations(example_func, {}, "clone_shallow", clone=True)
44+
# but let's test the flag logic in Variant
45+
wrapper = Variant(example_func, {}, "clone_shallow", clone=True)
4646
# function copy is same object
4747
self.assertEqual(wrapper.phlex_callable, example_func)
4848

@@ -51,7 +51,7 @@ class CallableObj:
5151
def __call__(self): pass
5252

5353
obj = CallableObj()
54-
wrapper_obj = AdjustAnnotations(obj, {}, "obj_clone", clone=True)
54+
wrapper_obj = Variant(obj, {}, "obj_clone", clone=True)
5555
self.assertNotEqual(id(wrapper_obj.phlex_callable), id(obj)) # copy was made?
5656
# copy.copy of a custom object usually creates a new instance if generic
5757

@@ -62,7 +62,7 @@ def __init__(self): self.data = [1]
6262
def __call__(self): return self.data[0]
6363

6464
c = Container()
65-
wrapper = AdjustAnnotations(c, {}, "deep_clone", clone="deep")
65+
wrapper = Variant(c, {}, "deep_clone", clone="deep")
6666
self.assertNotEqual(id(wrapper.phlex_callable), id(c))
6767
self.assertNotEqual(id(wrapper.phlex_callable.data), id(c.data))
6868

0 commit comments

Comments
 (0)