Ghidra is a software reverse engineering (SRE) framework
Fix Python type annotations in PyGhidra module when using `contextmanager`
Nicolas Ioossfc0f971c3924
diff --git a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/api.py b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/api.pyindex b5b13d608e..7e396fc698 100644--- a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/api.py+++ b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/api.py@@ -15,7 +15,7 @@##import sysimport contextlib-from typing import Union, TYPE_CHECKING, Tuple, List, Callable, Any, Optional+from typing import Union, TYPE_CHECKING, Tuple, List, Callable, Generator, Any, Optionalfrom pyghidra.converters import * # pylint: disable=wildcard-import, unused-wildcard-import@@ -142,7 +142,7 @@ def consume_program(def program_context(project: "Project",path: Union[str, Path],- ) -> "Program":+ ) -> Generator["Program", None, None]:"""Gets the Ghidra program from the given project with the given project path. The returnedprogram's resource cleanup is performed by a context manager.@@ -256,7 +256,7 @@ def ghidra_script(def transaction(program: "Program",description: str = "Unnamed Transaction"- ):+ ) -> Generator[int, None, None]:"""Creates a context for running a Ghidra transaction.diff --git a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/core.py b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/core.pyindex 04938d7034..81858670cc 100644--- a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/core.py+++ b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/core.py@@ -15,7 +15,7 @@##import contextlibimport warnings-from typing import Union, TYPE_CHECKING, Tuple, ContextManager, List, Optional+from typing import Union, TYPE_CHECKING, Tuple, Generator, List, Optionalfrom pyghidra.converters import * # pylint: disable=wildcard-import, unused-wildcard-import@@ -179,7 +179,7 @@ def open_program(loader: Union[str, JClass] = None,program_name: str = None,nested_project_location = True-) -> ContextManager["FlatProgramAPI"]: # type: ignore+) -> Generator["FlatProgramAPI", None, None]:"""Opens given binary path (or optional program name) in Ghidra and returns FlatProgramAPI object.diff --git a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/internal/plugin/plugin.py b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/internal/plugin/plugin.pyindex 913b6e143e..b7629e021e 100644--- a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/internal/plugin/plugin.py+++ b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/internal/plugin/plugin.py@@ -22,6 +22,7 @@ import sysimport threadingimport typesfrom code import InteractiveConsole+from typing import Generatorfrom ghidra.app.script import ScriptControlsfrom ghidra.framework import Application@@ -276,7 +277,7 @@ class PyConsole(InteractiveConsole):self.reset()@contextlib.contextmanager- def redirect_writer(self):+ def redirect_writer(self) -> Generator[None, None, None]:self._writer = self._errtry:yield@@ -292,7 +293,7 @@ class PyConsole(InteractiveConsole):super().showtraceback()@contextlib.contextmanager- def _run_context(self):+ def _run_context(self) -> Generator[None, None, None]:self._script.start()success = Falsetry:diff --git a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/launcher.py b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/launcher.pyindex 31214c4b11..324365aee5 100644--- a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/launcher.py+++ b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/launcher.py@@ -29,7 +29,7 @@ import tempfileimport threadingfrom importlib.machinery import ModuleSpecfrom pathlib import Path-from typing import List, NoReturn, Tuple, Union+from typing import Generator, List, NoReturn, Tuple, Unionimport jpypefrom jpype import imports, _jpype@@ -43,7 +43,7 @@ logger = logging.getLogger(__name__)@contextlib.contextmanager-def _silence_java_output(stdout=True, stderr=True):+def _silence_java_output(stdout=True, stderr=True) -> Generator[None, None, None]:from java.io import OutputStream, PrintStream # type:ignore @UnresolvedImportfrom java.lang import System # type:ignore @UnresolvedImportout = System.out