Vector35 / Vector35/binaryninja-api
Python traverse functions have wrong type annotations
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 1.3k
- Forks
- 298
- Avg merge
- 5d 5h
- Merged PRs (30d)
- 19
Description
Version and Platform (required):
- Binary Ninja Version:
dev/5.2.8414
Bug Description:
The Python IL bindings have 6 traverse functions, with signatures like:
def traverse(self, cb: Callable[['HighLevelILInstruction', Any], Any], *args: Any, **kwargs: Any) -> Iterator[Any]:
As written, this expects the callback to take exactly two arguments, one of type HighLevelILInstruction and one of type Any. In reality, the callback is called with an arbitrary number of arguments: the instruction, plus whatever args and kwargs were passed to traverse. This causes spurious type errors in clients of the API if you pass a callback that takes a different number of arguments.
This can be properly typed with something like:
P = ParamSpec('P')
R = TypeVar('R')
def traverse(self, cb: Callable[Concatenate['HighLevelILInstruction', P], R], *args: P.args, **kwargs: P.kwargs) -> Iterator[R]:
This would work for 5 out of the 6 traverse functions, but not the one on HighLevelILInstruction, because it has an extra keyword-only argument shallow: bool = True which is not passed on to the callback. Unfortunately there is no way to express this situation with type annotations, so the arguments to traverse would still have to use Any. But it can at least be partly fixed:
P = ParamSpec('P')
R = TypeVar('R')
def traverse(self, cb: Callable[Concatenate['HighLevelILInstruction', P], R], *args: Any, shallow: bool = True, **kwargs: Any) -> Iterator[R]:
Contributor guide
No contributing guide indexed for this repository
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 locating the six Python IL traverse definitions in the bindings and compare their callback signatures, especially HighLevelILInstruction.traverse. Update the annotations according to the issue's proposed typing shapes, preserving shallow as a keyword-only argument where needed, and confirm callbacks with forwarded arguments no longer produce spurious type errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, developer-experience, reverse-engineering
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100