[BUG]: Inaccurate exception message for function/ method that needs unsigned int
Nobody has claimed this yet.
- 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
If I define a function or method that requires an unsigned value
void takes_unsigned(unsigned int x) {}
and add it to a pybind module
m.def("takes_unsigned", &takes_unsigned);
and call it from Python, but pass it a negative number
mymodule.takes_unsigned(-10)
, I get the following exception
TypeError: takes_unsigned(): incompatible function arguments. The following argument types are supported:
1. (arg0: int) -> None
Invoked with: -10
It's great that this case throws a TypeError since my argument was invalid. However, the error message says my call is wrong because the supported argument type is "int" and I invoked with -10 (which is an int). That is not really a description of what went wrong.
Reproducible example code
#include <pybind11/pybind11.h>
void takes_unsigned(unsigned int x) {}
PYBIND11_MODULE(mymodule, m) {
m.def("takes_unsigned", &takes_unsigned);
}
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
Reproduce the issue with the C++ function and Python call shown in the report, starting from pybind11/pybind11.h. Trace the argument-conversion and exception-message path to determine where an unsigned value is described as int. Done means the negative-argument failure explains the unsigned requirement accurately.
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
- 38/100