-
Notifications
You must be signed in to change notification settings - Fork 185
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
Guard against unused arguments in script interfae #4941
Comments
I'm not totally confident we can implement such behavior in the script interface. It was originally designed to emulate the behavior of a Python I can think of a few challenges to the deployment of the proposed solution:
I've thought about this issue in the past, but couldn't find satisfactory solutions:
Can we find examples of Python projects where |
Maybe we could adapt the automatic class method generation to something like: @script_interface_register
class Feature(ScriptInterfaceHelper):
def foo(self, kT=None, gamma=None):
kwargs = locals()
del kwargs["self"]
self.call_method("foo", **kwargs) This way, unexpected arguments always raise an exception. Maybe there is a way to express that in a more compact form with a decorator. The danger with such a solution is that Here is a MWE to check the output of import unittest
global_var = 5
class P:
def foo(self, a, b=None):
c = a
print(locals())
P().foo(1, b=3) Output:
|
Following up to the removed act_on_virtual in the lb thermostat.
A solution we could investigate is to use a wrapper around the VariantMap holding the parameters which keeps track of consumed parameters and throws in the destructor if something wasn't consumed.
VariantMap is a std::unorderd_map<string, Variant>.
Chatgpt came up with the following, which at least convesys the idea.
Prompt: Write a wrapper around std::unordered_map, which keeps trakc on which elements have been accessed and throws in the destructor if not all elements were used
Here is a wrapper around
std::unordered_map
that keeps track of which elements have been accessed and throws an exception in the destructor if not all elements were used.The text was updated successfully, but these errors were encountered: