Closed mkolin closed 2 years ago
What is the motivating use case? None
plays a lot of roles in Python and giving it all the same roles in C++ has been a source of trouble (e.g. overload resolution and use of return types), so over time, I've been restricting it further and further to eventually only mean void
.
Oftentimes, we have a python wrapper function that has a similar signature. It would be nice to just pass the params in as is.
def func_with_optional_param(x, y=None):
FuncWithOptionalParam(x, y)
Right now there has to be some sort of check for None
. It's not really necessary, just a nice to have. I understand not wanting to use None
in more cases, though.
Where is None
coming from? Is it written like in the code snippet above? If yes, then a simpler solution, one with no possibility for confusion, is to create a new magic variable called cppyy.default
which then is interpreted as "result of the default constructor" which for an int
argument means int()
i.e. 0
of type int
.
Thanks! We can give that a try.
It doesn't exist yet. :) If this is a workable idea, it's trivial to implement, though.
This library has been pretty amazing. A nice enhancement would be to convert a python None to a default parameter in C++:
Not important at all, but it would be great if the last call would instantiate
FuncWithOptionalParam(1, 0)
.