Skip to content

Is it possible to ensure that std::optional<T> arguments always have .none() ? #82

Answered by wjakob
MatthiasKohl asked this question in Q&A
Discussion options

You must be logged in to vote

Yeah, it's something that slightly bothered me as well. I cannot think of an elegant way, which is why it probably wasn't part of the original PR #67.

A hacky way to comes in mind would be to add some extra processing to nb_func_new() (which is called whenever we bind a C++ function into the Python world).

For functions with explicit nb::arg values, we would need to do a sweep over descr and mark the associated entry as None-compatible when encountering {Optional[ in the string. For functions that don't have nb::arg values, we would do the same thing but create unnamed arguments on the fly and attach them to the function.

Ideally this processing could be done in a separate function to avo…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@wjakob
Comment options

@MatthiasKohl
Comment options

Answer selected by wjakob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants