-
Notifications
You must be signed in to change notification settings - Fork 14
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
Constraint checking on dictionary-class converter #31
Comments
Why would you want to make this part of the conversion and not check these things in the actual function body? |
I'm sure are several design options here (including ones I've not thought of). I view this as a pre-condition (expects) / post-condition (ensures) question: The way the current interface (CPP2PY_ARG_AS_DICT) seems designed with the idea of always passing a single parameters to a single function. Here it is natural a pre-condition (expects) check on that input in the function. I guess this is the way you phrased the question above. However we could also think of the conversion as a (complicated) constructor from of the c++ class inputting a python dict. Then it makes sense to think about checking validity as a post-condition on the ctor (ensures). But right now, I don't know if the user can specify such a post-condition. [Personally, I like to separate conversion (ctor) and passing the data to a separate function. This is also why I suggest the keyword changes in #30. But this is not so important here.] Pre-condition/post-condition is in a sense a matter of taste.
|
Hi,
I wanted to run an idea by you to see if it would be interesting thing to implement.
I remember that when you have a convertor from python to cpp (via CPP2PY_ARG_AS_DICT), it does type checking of the input to make sure everything is well defined.
Would it also be possible to specify additional constraints / bounds / traits during this conversion?
For example, it would be nice to specify something that a parameter (e.g. temperature) should be > 0. This is then checked on conversion and gives an error message if it fails.
Or would this cause other problems?
Thanks!
The text was updated successfully, but these errors were encountered: