mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-08-08 07:40:39 -09:00
Verifying the type annotations used by PyGhidra with Mypy static type
checker leads to the following error:
core.py:171: error: Argument 1 to "contextmanager" has incompatible
type "Callable[[str | Path, str | Path, str, Any, str, str, str |
JClass, str, Any], AbstractContextManager[Any, bool | None]]";
expected "Callable[[str | Path, str | Path, str, Any, str, str, str
| JClass, str, Any], Iterator[Never]]" [arg-type]
Indeed, in Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/core.py,
function open_program was declared to return a
ContextManager["FlatProgramAPI"]. While this function indeed returns
such a type, the implementation uses decorator @contextlib.contextmanager
which expects the wrapped function to return an generator (with yield).
Use Generator["FlatProgramAPI", None, None] to fix this.
While at it, fix other locations where the type annotation of the
function wrapped with contextmanager was incorrect.