You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some programming languages (e.g. Python) have support for keyword arguments, in addition to only ordered arguments. Furthermore, in Python at least, one can have a function with keyword only arguments, which can happen if an argument follows the varargs *args syntax, or in general for the **kwargs syntax. In either situation, the name of the parameter must be given along with the intended value.
SciJava Ops currently does not have a feature like this, but it could. Here is one possible syntax:
In the example above, the image and sigma parameters are individually given by separate .input(name, value) calls. A big advantage of this design is that it preserves the type safety offered by Ops. A downside is that the OpBuilder infrastructure would need to expand a lot to accommodate it. Another difficulty is that the op matching engine is currently fully built around the idea of ordered parameters, and it would need refactoring to support op requests with unordered+named inputs. But all of that could certainly be done with effort.
This goal of supporting op matching by named inputs would make it more elegant to wrap such Python functions into Ops. But even with it in place, Ops does not support varargs and might never do so, since it weakens type safety.
I appreciate your solution, however for completeness I'll write down another solution - simply treat keyword-only arguments as positional arguments. At the end of the day, we'll need Python-based OpInfo objects that will have to know how to make Ops capable of calling Python code - they could give the impression of required positional arguments that get permuted into keyword-only arguments. The main benefit of this course of action is no additional API, and no changes to the matcher. This may be a good first attempt targeted for minimal effort and refactored later if insufficient.
Activity
gselzer commentedon Jul 31, 2024
I appreciate your solution, however for completeness I'll write down another solution - simply treat keyword-only arguments as positional arguments. At the end of the day, we'll need Python-based
OpInfoobjects that will have to know how to make Ops capable of calling Python code - they could give the impression of required positional arguments that get permuted into keyword-only arguments. The main benefit of this course of action is no additional API, and no changes to the matcher. This may be a good first attempt targeted for minimal effort and refactored later if insufficient.