Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions test/python/reducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ def add(i: int, j: int) -> int:
return i + j


def add_sum01(sum0: int, sum1: int) -> int:
"""Add sum0 and sum1."""
return sum0 + sum1


def add_sum23(sum2: int, sum3: int) -> int:
"""Add sum2 and sum3."""
return sum2 + sum3


def add_final(sum01: int, sum23: int) -> int:
"""Add sum01 and sum23."""
return sum01 + sum23


def PHLEX_REGISTER_ALGORITHMS(m, config):
"""Register a series of `add` algorithm as transformations.

Expand All @@ -55,8 +70,8 @@ def PHLEX_REGISTER_ALGORITHMS(m, config):
)

# now reduce them pair-wise
m.transform(add, name="reduce01", input_family=["sum0", "sum1"], output_products=["sum01"])
m.transform(add, name="reduce23", input_family=["sum2", "sum3"], output_products=["sum23"])
m.transform(add_sum01, name="reduce01", input_family=["sum0", "sum1"], output_products=["sum01"])
m.transform(add_sum23, name="reduce23", input_family=["sum2", "sum3"], output_products=["sum23"])

# once more (and the configuration will add a verifier)
m.transform(add, name="reduce", input_family=["sum01", "sum23"], output_products=["sum"])
m.transform(add_final, name="reduce", input_family=["sum01", "sum23"], output_products=["sum"])
22 changes: 13 additions & 9 deletions test/python/test_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,43 @@


# 3-argument function to trigger py_callback<3>
def sum_three(a: int, b: int, c: int) -> int:
def sum_three(i: int, j: int, k: int) -> int:
"""Sum three integers."""
return a + b + c
return i + j + k


# Function that raises exception to test error handling
def raise_error(a: int) -> int:
def raise_error(i: int) -> int:
"""Raise a RuntimeError."""
raise RuntimeError("Intentional failure")


# Invalid bool return (2)
def bad_bool(a: int) -> bool:
def bad_bool(i: int) -> bool:
"""Return an invalid boolean value."""
return 2 # type: ignore


# Invalid long return (float)
def bad_long(a: int) -> "long": # type: ignore # noqa: F821
def bad_long(i: int) -> "long": # type: ignore # noqa: F821
"""Return a float instead of an int."""
return 1.5 # type: ignore


# Invalid uint return (negative)
def bad_uint(a: int) -> "unsigned int": # type: ignore # noqa: F722
def bad_uint(i: int) -> "unsigned int": # type: ignore # noqa: F722
"""Return a negative value for unsigned int."""
return -5 # type: ignore


# Function with mismatching annotation count vs config inputs
def two_args(a: int, b: int) -> int:
"""Sum two integers."""
return a + b
def two_args(i: int, j: int, k: int) -> int: # noqa: ARG001
"""Sum only the first two of three integers (tests parameter count mismatch).

Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

There is trailing whitespace on the blank line inside this docstring (violates the repo formatting rules and can fail whitespace checks). Remove the spaces so the line is empty.

Suggested change

Copilot uses AI. Check for mistakes.
Note: Parameter k is intentionally unused - this tests that the function
accepts 3 parameters to match input_family but doesn't use all of them.
"""
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

two_args is used by pymismatch_variant.jsonnet, which intentionally provides 3 inputs to a 2-argument function to trigger the "number of inputs ... does not match number of annotation types" failure. Changing the signature to accept 3 parameters (and annotating all 3) removes that mismatch and will cause py:mismatch_variant to stop failing as expected. Keep two_args at 2 parameters (but rename them to match the input labels, e.g., i and j) so the config's extra k still triggers the mismatch error.

Suggested change
def two_args(i: int, j: int, k: int) -> int: # noqa: ARG001
"""Sum only the first two of three integers (tests parameter count mismatch).
Note: Parameter k is intentionally unused - this tests that the function
accepts 3 parameters to match input_family but doesn't use all of them.
"""
def two_args(i: int, j: int) -> int:
"""Sum two integers while config provides three inputs (tests parameter count mismatch)."""

Copilot uses AI. Check for mistakes.
return i + j


def PHLEX_REGISTER_ALGORITHMS(m, config):
Expand Down
8 changes: 4 additions & 4 deletions test/python/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ def collect_int(i: int) -> list[int]:
return [i]


def collect_float(f: float) -> list[float]:
def collect_float(f1: float) -> list[float]:
"""Collect a float into a list."""
return [f]
return [f1]


def collect_double(d: "double") -> "list[double]": # type: ignore
def collect_double(d1: "double") -> "list[double]": # type: ignore
"""Collect a double into a list."""
return [d]
return [d1]


def PHLEX_REGISTER_ALGORITHMS(m, config):
Expand Down
2 changes: 1 addition & 1 deletion test/python/test_mismatch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Test mismatch between input labels and types."""


def mismatch_func(a: int, b: int):
def mismatch_func(a: int, b: int) -> int:
"""Add two integers."""
return a + b

Expand Down
48 changes: 24 additions & 24 deletions test/python/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,82 +14,82 @@ class double(float): # noqa: N801
pass


def add_float(i: float, j: float) -> float:
def add_float(f1: float, f2: float) -> float:
"""Add two floats.

Args:
i (float): First input.
j (float): Second input.
f1 (float): First input.
f2 (float): Second input.

Returns:
float: Sum of the two inputs.
"""
return i + j
return f1 + f2


def add_double(i: double, j: double) -> double:
def add_double(d1: double, d2: double) -> double:
"""Add two doubles.

Args:
i (float): First input.
j (float): Second input.
d1 (float): First input.
d2 (float): Second input.

Returns:
float: Sum of the two inputs.
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

The add_double docstring still describes the parameters/return as float, but the function signature/return type are double. Update the docstring types so they match what the function actually accepts/returns.

Suggested change
d1 (float): First input.
d2 (float): Second input.
Returns:
float: Sum of the two inputs.
d1 (double): First input.
d2 (double): Second input.
Returns:
double: Sum of the two inputs.

Copilot uses AI. Check for mistakes.
"""
return double(i + j)
return double(d1 + d2)


def add_unsigned(i: "unsigned int", j: "unsigned int") -> "unsigned int": # type: ignore # noqa: F722
def add_unsigned(u1: "unsigned int", u2: "unsigned int") -> "unsigned int": # type: ignore # noqa: F722
"""Add two unsigned integers.

Args:
i (int): First input.
j (int): Second input.
u1 (int): First input.
u2 (int): Second input.

Returns:
int: Sum of the two inputs.
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

The add_unsigned docstring says the return type is int, but the function is annotated to return "unsigned int". Update the docstring return type/description so it matches the annotation.

Suggested change
u1 (int): First input.
u2 (int): Second input.
Returns:
int: Sum of the two inputs.
u1 ("unsigned int"): First input.
u2 ("unsigned int"): Second input.
Returns:
"unsigned int": Sum of the two inputs.

Copilot uses AI. Check for mistakes.
"""
return i + j
return u1 + u2


def collect_float(i: float, j: float) -> npt.NDArray[np.float32]:
def collect_float(f1: float, f2: float) -> npt.NDArray[np.float32]:
"""Combine floats into a numpy array.

Args:
i (float): First input.
j (float): Second input.
f1 (float): First input.
f2 (float): Second input.

Returns:
ndarray: Array of floats.
"""
return np.array([i, j], dtype=np.float32)
return np.array([f1, f2], dtype=np.float32)


def collect_double(i: double, j: double) -> npt.NDArray[np.float64]:
def collect_double(d1: double, d2: double) -> npt.NDArray[np.float64]:
"""Combine doubles into a numpy array.

Args:
i (float): First input.
j (float): Second input.
d1 (float): First input.
d2 (float): Second input.
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

The collect_double docstring lists argument types as float, but the function takes double objects. Update the docstring types to match the signature.

Suggested change
d1 (float): First input.
d2 (float): Second input.
d1 (double): First input.
d2 (double): Second input.

Copilot uses AI. Check for mistakes.

Returns:
ndarray: Array of doubles.
"""
return np.array([i, j], dtype=np.float64)
return np.array([d1, d2], dtype=np.float64)


def and_bool(i: bool, j: bool) -> bool:
def and_bool(b1: bool, b2: bool) -> bool:
"""And two booleans.

Args:
i (bool): First input.
j (bool): Second input.
b1 (bool): First input.
b2 (bool): Second input.

Returns:
bool: Logical AND of the two inputs.
"""
return i and j
return b1 and b2


def PHLEX_REGISTER_ALGORITHMS(m, config):
Expand Down
48 changes: 24 additions & 24 deletions test/python/vectypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,21 @@ def sum_array_int32(coll: npt.NDArray[np.int32]) -> int:


def collectify_uint32(
i: unsigned_int,
j: unsigned_int,
u1: unsigned_int,
u2: unsigned_int,
) -> npt.NDArray[np.uint32]:
"""Create a uint32 array from two integers."""
return np.array([i, j], dtype=np.uint32)
return np.array([u1, u2], dtype=np.uint32)


def sum_array_uint32(coll: npt.NDArray[np.uint32]) -> unsigned_int:
"""Sum a uint32 array."""
return unsigned_int(sum(int(x) for x in coll))


def collectify_int64(i: long, j: long) -> npt.NDArray[np.int64]:
def collectify_int64(l1: long, l2: long) -> npt.NDArray[np.int64]:
"""Create an int64 array from two integers."""
return np.array([i, j], dtype=np.int64)
return np.array([l1, l2], dtype=np.int64)


def sum_array_int64(coll: npt.NDArray[np.int64]) -> long:
Expand All @@ -82,41 +82,41 @@ def sum_array_int64(coll: npt.NDArray[np.int64]) -> long:


def collectify_uint64(
i: unsigned_long,
j: unsigned_long,
ul1: unsigned_long,
ul2: unsigned_long,
) -> npt.NDArray[np.uint64]:
"""Create a uint64 array from two integers."""
return np.array([i, j], dtype=np.uint64)
return np.array([ul1, ul2], dtype=np.uint64)


def sum_array_uint64(coll: npt.NDArray[np.uint64]) -> unsigned_long:
"""Sum a uint64 array."""
return unsigned_long(sum(int(x) for x in coll))


def collectify_float32(i: float, j: float) -> npt.NDArray[np.float32]:
def collectify_float32(f1: float, f2: float) -> npt.NDArray[np.float32]:
"""Create a float32 array from two floats."""
return np.array([i, j], dtype=np.float32)
return np.array([f1, f2], dtype=np.float32)


def sum_array_float32(coll: npt.NDArray[np.float32]) -> float:
"""Sum a float32 array."""
return float(sum(coll))


def collectify_float64(i: double, j: double) -> npt.NDArray[np.float64]:
def collectify_float64(d1: double, d2: double) -> npt.NDArray[np.float64]:
"""Create a float64 array from two floats."""
return np.array([i, j], dtype=np.float64)
return np.array([d1, d2], dtype=np.float64)


def collectify_float32_list(i: float, j: float) -> list[float]:
def collectify_float32_list(f1: float, f2: float) -> list[float]:
"""Create a float32 list from two floats."""
return [i, j]
return [f1, f2]


def collectify_float64_list(i: double, j: double) -> list["double"]:
def collectify_float64_list(d1: double, d2: double) -> list["double"]:
"""Create a float64 list from two floats."""
return [i, j]
return [d1, d2]


def sum_array_float64(coll: npt.NDArray[np.float64]) -> double:
Expand All @@ -130,24 +130,24 @@ def collectify_int32_list(i: int, j: int) -> list[int]:


def collectify_uint32_list(
i: unsigned_int,
j: unsigned_int,
u1: unsigned_int,
u2: unsigned_int,
) -> "list[unsigned int]": # type: ignore # noqa: F722
"""Create a uint32 list from two integers."""
return [unsigned_int(i), unsigned_int(j)]
return [unsigned_int(u1), unsigned_int(u2)]


def collectify_int64_list(i: long, j: long) -> "list[long]": # type: ignore # noqa: F722
def collectify_int64_list(l1: long, l2: long) -> "list[long]": # type: ignore # noqa: F722
"""Create an int64 list from two integers."""
return [long(i), long(j)]
return [long(l1), long(l2)]


def collectify_uint64_list(
i: unsigned_long,
j: unsigned_long,
ul1: unsigned_long,
ul2: unsigned_long,
) -> "list[unsigned long]": # type: ignore # noqa: F722
"""Create a uint64 list from two integers."""
return [unsigned_long(i), unsigned_long(j)]
return [unsigned_long(ul1), unsigned_long(ul2)]


def sum_list_int32(coll: list[int]) -> int:
Expand Down
Loading
Loading