[BUG]: C++ instance passed as pointer not marked as optional in function signature
Open
Nobody has claimed this yet.
signatures
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
Problem description
When passing a C++ instance as a pointer, the default behaviour is to accept None as described in the documentation. Consider the following example:
py::class_<Dog>(m, "Dog").def(py::init<>());
m.def("bark",
[](const Dog* dog) { return dog ? "woof!" : "(no dog)"; },
py::arg("dog")=py::none());
The function signature in help(module) looks like this:
FUNCTIONS
bark(...) method of builtins.PyCapsule instance
bark(dog: module.Dog = None) -> str
but we would expect this signature instead:
FUNCTIONS
bark(...) method of builtins.PyCapsule instance
bark(dog: Optional[module.Dog] = None) -> str
I tested with pybind11 2.7.1.
Reproducible example code
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the documented allow/prohibiting None behavior and reproduce the supplied m.def("bark", ...) example, then inspect how help(module) renders the pointer argument in the function signature. Done means the signature shows Optional[module.Dog] for the nullable pointer while preserving the default None behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100