diff mbox series

[09/11] qapi/gen: Support for switching to another module temporarily

Message ID 20201218205407.1326907-10-armbru@redhat.com
State New
Headers show
Series Drop support for QAPIGen without a file name | expand

Commit Message

Markus Armbruster Dec. 18, 2020, 8:54 p.m. UTC
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 scripts/qapi/gen.py | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

John Snow Jan. 15, 2021, 2:07 a.m. UTC | #1
On 12/18/20 3:54 PM, Markus Armbruster wrote:
> +    @contextmanager
> +    def _temp_module(self, name: str) -> ContextManager[None]:

Doesn't quite typecheck; we want Iterator[None] -- I think we're typing 
the function that is yet-to-be-decorated -- mypy will handle typing the 
resulting function.

--js
diff mbox series

Patch

diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py
index d9f8bac9aa..cb00229f5d 100644
--- a/scripts/qapi/gen.py
+++ b/scripts/qapi/gen.py
@@ -15,6 +15,7 @@  from contextlib import contextmanager
 import os
 import re
 from typing import (
+    ContextManager,
     Dict,
     Iterator,
     List,
@@ -296,6 +297,13 @@  class QAPISchemaModularCVisitor(QAPISchemaVisitor):
         self._module[name] = (genc, genh)
         self._current_module = name
 
+    @contextmanager
+    def _temp_module(self, name: str) -> ContextManager[None]:
+        old_module = self._current_module
+        self._current_module = name
+        yield
+        self._current_module = old_module
+
     def write(self, output_dir: str, opt_builtins: bool = False) -> None:
         for name in self._module:
             if self._is_builtin_module(name) and not opt_builtins: