Strict func(ctx) signature validation rejects valid matcher functions
The matcher_factory validator in _resolver.py requires the imported function to have exactly one parameter named ctx:
@pydantic.field_validator("matcher_factory", mode="after")
@classmethod
def validate_matcher(cls, value: typing.Callable) -> typing.Callable:
sig = inspect.signature(value)
if list(sig.parameters) != ["ctx"]:
raise TypeError(
f"{value} has an invalid signature {sig}, expected 'func(ctx)'."
)
return value
Problem1: Any existing matcher function that has additional parameters (even with defaults) is rejected. For example, a reusable matcher function like:
def tag_matcher(
accelerator: str | None = None,
filter_by_accelerator: bool = False,
) -> resolver.MatchFunction:
...
Cannot be referenced from YAML, even though calling it with no arguments would work perfectly. Users are forced to write trivial wrapper functions for every matcher they want to use:
def tag_matcher_factory(ctx):
return tag_matcher()
This adds boilerplate and reduces the value of the declarative config.
Problem 2: No mechanism to pass arguments to matcher factories via YAML
Even with relaxed validation, there is no way to pass non-default arguments to a matcher function from YAML. The matcher_factory field is a plain import string with no argument support.
For example, if a user wants to filter tags by accelerator:
This works in a plugin:
matcher = tag_matcher(accelerator="cuda", filter_by_accelerator=True)
But there's no YAML equivalent — this is just a function reference:
matcher_factory: my_package.matchers:tag_matcher
Strict func(ctx) signature validation rejects valid matcher functions
The matcher_factory validator in _resolver.py requires the imported function to have exactly one parameter named ctx:
Problem1: Any existing matcher function that has additional parameters (even with defaults) is rejected. For example, a reusable matcher function like:
def tag_matcher(
accelerator: str | None = None,
filter_by_accelerator: bool = False,
) -> resolver.MatchFunction:
...
Cannot be referenced from YAML, even though calling it with no arguments would work perfectly. Users are forced to write trivial wrapper functions for every matcher they want to use:
def tag_matcher_factory(ctx):
return tag_matcher()
This adds boilerplate and reduces the value of the declarative config.
Problem 2: No mechanism to pass arguments to matcher factories via YAML
Even with relaxed validation, there is no way to pass non-default arguments to a matcher function from YAML. The matcher_factory field is a plain import string with no argument support.
For example, if a user wants to filter tags by accelerator:
This works in a plugin:
matcher = tag_matcher(accelerator="cuda", filter_by_accelerator=True)
But there's no YAML equivalent — this is just a function reference:
matcher_factory: my_package.matchers:tag_matcher