Missing argument error messages should be closer to python's
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Issue description
When a user neglects to provide the correct number of arguments, pybind11 gives a different error message than that which python users might expect. In my opinion, the python error message is clearer.
Reproducible example code
int add(int i, int j) {
return i + j;
}
def pyadd(i, j):
return i + j
So if I call the python snippet:
>>> pyadd(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: pyadd() missing 1 required positional argument: 'j'
Whereas the pybind11 snippet is:
>>> add(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: add(): incompatible function arguments. The following argument types are supported:
1. (i: int, j: int) -> int
Invoked with: 1
Now, this isn't a great example because the types are really short. But as a user, the first thing that I'm scanning for is the types and whether my types match -- it takes some effort to figure out the number is incorrect. Here's a more real example from pybind11:
Traceback (most recent call last):
File "C:\Users\first\AppData\Local\Programs\Python\Python38\lib\site-packages\wpilib\_impl\start.py", line 106, in start
self.robot.startCompetition()
File "robot.py", line 84, in teleopPeriodic
self.drive.arcadeDrive(self.trig, self.con0.getX())
TypeError: getX(): incompatible function arguments. The following argument types are supported:
1. (self: wpilib._wpilib.XboxController, hand: wpilib.interfaces._interfaces.GenericHID.Hand) -> float
Invoked with: <wpilib._wpilib.XboxController object at 0x0000022286350F30>
There's a lot of punctuation in that error message, and the actual issue (missing argument) is obscured by everything. This gets worse as the number of arguments increases.
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 by tracing pybind11's argument-count error formatting and compare its output with the Python TypeError examples in the issue. Determine how missing positional arguments should be distinguished from type mismatches and define done as a clearer diagnostic that identifies the missing arguments without obscuring supported signatures.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100