qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 12/25] qapi/schema.py: remove 'and' from non-bool rvalue expressi


From: John Snow
Subject: [PATCH 12/25] qapi/schema.py: remove 'and' from non-bool rvalue expressions
Date: Tue, 22 Sep 2020 18:44:48 -0400

There's nothing inherently wrong with using 'and' in this manner, but
the type returned is more loose than you might expect. Any value can be
false-ish, so mypy assumes that the type of the expression must be the
Union of both types, because a type can always be false-ish.

To tighten the static analysis type, we have to use the slightly
clunkier but more formally correct ternary.

Fixes these errors:

qapi/schema.py:103: error: Argument 1 to "module_by_fname" of "QAPISchema" has
    incompatible type "Union[QAPISourceInfo, str]"; expected "Optional[str]"

qapi/schema.py:380: error: Argument 3 to "resolve_type" of "QAPISchema" has
    incompatible type "Union[QAPISourceInfo, str]";
    expected "Union[str, Callable[[Optional[QAPISourceInfo]], str], None]"

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

diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
index 57343a1002..943f234ee2 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -81,7 +81,7 @@ def check_doc(self):
 
     def _set_module(self, schema, info):
         assert self._checked
-        self._module = schema.module_by_fname(info and info.fname)
+        self._module = schema.module_by_fname(info.fname if info else None)
         self._module.add_entity(self)
 
     def set_module(self, schema):
@@ -305,7 +305,7 @@ def check(self, schema):
         super().check(schema)
         self.element_type = schema.resolve_type(
             self._element_type_name, self.info,
-            self.info and self.info.defn_meta)
+            self.info.defn_meta if self.info else None)
         assert not isinstance(self.element_type, QAPISchemaArrayType)
 
     def set_module(self, schema):
-- 
2.26.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]