Skip to content
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

Replace sentinel arguments and return values with std::optional #3413

Open
jhale opened this issue Sep 17, 2024 · 1 comment
Open

Replace sentinel arguments and return values with std::optional #3413

jhale opened this issue Sep 17, 2024 · 1 comment
Labels
enhancement New feature or request housekeeping Tidying and style improvements

Comments

@jhale
Copy link
Member

jhale commented Sep 17, 2024

Describe new/missing feature

std::optional provides a modern way to express passing or returning value or not computed.

We are currently using many sentinel function arguments and return values including -1, nullptr and empty strings that require the user to read the docstring of the function to understand the argument or return value. These can be replaced with std::optional which is very explicit. An additional advantage is that nanobind has support for std::optional which results in consistent behaviour between the Python (typing.Optional) and C++ interfaces and a reduction in Python wrapper code complexity.

A first step would be identifying all typing.Optional arguments in Python which typically leads to a sentinel in C++.

Examples of use are here:

#3328
#3322

Suggested user interface

No response

@jhale jhale added enhancement New feature or request housekeeping Tidying and style improvements labels Sep 17, 2024
@schnellerhase
Copy link
Contributor

schnellerhase commented Sep 19, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request housekeeping Tidying and style improvements
Projects
None yet
Development

No branches or pull requests

2 participants