[PATCH 10/14] qapi/gen.py: Add __bool__ dunder method to QAPIGen

John Snow posted 14 patches 5 years, 4 months ago
There is a newer version of this series
[PATCH 10/14] qapi/gen.py: Add __bool__ dunder method to QAPIGen
Posted by John Snow 5 years, 4 months ago
Falseish when there is no body or preamble; Trueish when there is.
Header and footer are excluded for now, because they are assumed to be
dynamic and always present.

Signed-off-by: John Snow <jsnow@redhat.com>
---
 scripts/qapi/gen.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py
index ed498397ad..892d7d772e 100644
--- a/scripts/qapi/gen.py
+++ b/scripts/qapi/gen.py
@@ -40,6 +40,9 @@ def __init__(self, fname: Optional[str]):
         self._preamble = ''
         self._body = ''
 
+    def __bool__(self) -> bool:
+        return bool(self._preamble or self._body)
+
     def preamble_add(self, text: str) -> None:
         self._preamble += text
 
-- 
2.26.2


Re: [PATCH 10/14] qapi/gen.py: Add __bool__ dunder method to QAPIGen
Posted by Eduardo Habkost 5 years, 4 months ago
On Tue, Sep 22, 2020 at 05:17:58PM -0400, John Snow wrote:
> Falseish when there is no body or preamble; Trueish when there is.
> Header and footer are excluded for now, because they are assumed to be
> dynamic and always present.
> 
> Signed-off-by: John Snow <jsnow@redhat.com>

Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>

-- 
Eduardo