[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
- [PATCH 03/25] qapi/schema.py: add assert in stub methods, (continued)
- [PATCH 03/25] qapi/schema.py: add assert in stub methods, John Snow, 2020/09/22
- [PATCH 02/25] qapi/schema.py: Move meta-type into class instances, John Snow, 2020/09/22
- [PATCH 04/25] qapi/schema.py: constrain QAPISchemaObjectType base type, John Snow, 2020/09/22
- [PATCH 06/25] qapi/schema.py: constrain QAPISchemaEvent arg_type type, John Snow, 2020/09/22
- [PATCH 05/25] qapi/schema.py: constrain QAPISchemaObjectTypeMember arg_type type, John Snow, 2020/09/22
- [PATCH 09/25] qapi/schema.py: remove superfluous assert, John Snow, 2020/09/22
- [PATCH 07/25] qapi/schema.py: constrain tag_member type, John Snow, 2020/09/22
- [PATCH 14/25] qapi/schema.py: Assert variants of an object are also objects, John Snow, 2020/09/22
- [PATCH 10/25] qapi/schema.py: Add assertion to ifcond property, John Snow, 2020/09/22
- [PATCH 21/25] qapi/schema.py: disable pylint line limit, John Snow, 2020/09/22
- [PATCH 12/25] qapi/schema.py: remove 'and' from non-bool rvalue expressions,
John Snow <=
- [PATCH 11/25] qapi/schema.py: Constrain type of QAPISchemaObjectType members field, John Snow, 2020/09/22
- [PATCH 08/25] qapi/schema.py: Allow alternate_type to assert, John Snow, 2020/09/22
- [PATCH 13/25] qapi/schema.py: Test type of self.ret_type instead of local temp, John Snow, 2020/09/22
- [PATCH 16/25] qapi/schema.py: enable checking, John Snow, 2020/09/22
- [PATCH 24/25] qapi/schema.py: Add module docstring, John Snow, 2020/09/22
- [PATCH 20/25] qapi/schema.py: Replace one-letter variable names, John Snow, 2020/09/22
- [PATCH 18/25] qapi/schema.py: Add pylint warning suppressions, John Snow, 2020/09/22
- [PATCH 25/25] qapi/schema.py: Use python3 style super(), John Snow, 2020/09/22
- [PATCH 23/25] qapi/schema.py: enable pylint checks, John Snow, 2020/09/22
- [PATCH 19/25] qapi/schema.py: Convert several methods to classmethods, John Snow, 2020/09/22