[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 10/19] qapi: use schema.resolve_type instead of schema.lookup_
|
From: |
John Snow |
|
Subject: |
[PATCH v2 10/19] qapi: use schema.resolve_type instead of schema.lookup_type |
|
Date: |
Fri, 12 Jan 2024 17:29:36 -0500 |
lookup_type() is capable of returning None, but some callers aren't
prepared for that and assume it will always succeed.
Use the must-not-fail variant resolve_type() instead, which guarantees
that the return type will not be None.
Signed-off-by: John Snow <jsnow@redhat.com>
---
scripts/qapi/introspect.py | 4 ++--
scripts/qapi/schema.py | 3 +--
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py
index 67c7d89aae0..c38df61a6d5 100644
--- a/scripts/qapi/introspect.py
+++ b/scripts/qapi/introspect.py
@@ -227,10 +227,10 @@ def _use_type(self, typ: QAPISchemaType) -> str:
# Map the various integer types to plain int
if typ.json_type() == 'int':
- typ = self._schema.lookup_type('int')
+ typ = self._schema.resolve_type('int')
elif (isinstance(typ, QAPISchemaArrayType) and
typ.element_type.json_type() == 'int'):
- typ = self._schema.lookup_type('intList')
+ typ = self._schema.resolve_type('intList')
# Add type to work queue if new
if typ not in self._used_types:
self._used_types.append(typ)
diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
index a77b51d1b96..35638c7708a 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -650,8 +650,7 @@ def check(self, schema, seen):
"discriminator '%s' is not a member of %s"
% (self._tag_name, base))
# Here we do:
- base_type = schema.lookup_type(self.tag_member.defined_in)
- assert base_type
+ base_type = schema.resolve_type(self.tag_member.defined_in)
if not base_type.is_implicit():
base = "base type '%s'" % self.tag_member.defined_in
if not isinstance(self.tag_member.type, QAPISchemaEnumType):
--
2.43.0
- Re: [PATCH v2 11/19] qapi/schema: fix QAPISchemaArrayType.check's call to resolve_type, (continued)
[PATCH v2 14/19] qapi/schema: fix typing for QAPISchemaVariants.tag_member, John Snow, 2024/01/12
[PATCH v2 15/19] qapi/schema: assert inner type of QAPISchemaVariants in check_clash(), John Snow, 2024/01/12
[PATCH v2 12/19] qapi/schema: assert info is present when necessary, John Snow, 2024/01/12
[PATCH v2 18/19] qapi/schema: turn on mypy strictness, John Snow, 2024/01/12
[PATCH v2 19/19] qapi/schema: remove unnecessary asserts, John Snow, 2024/01/12
[PATCH v2 10/19] qapi: use schema.resolve_type instead of schema.lookup_type,
John Snow <=
[PATCH v2 07/19] qapi/schema: adjust type narrowing for mypy's benefit, John Snow, 2024/01/12
[PATCH v2 16/19] qapi/parser: demote QAPIExpression to Dict[str, Any], John Snow, 2024/01/12
[PATCH v2 09/19] qapi/schema: allow resolve_type to be used for built-in types, John Snow, 2024/01/12
[PATCH v2 03/19] qapi: create QAPISchemaDefinition, John Snow, 2024/01/12