[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 08/19] qapi/schema: add static typing and assertions to lookup_ty
|
From: |
John Snow |
|
Subject: |
[PATCH 08/19] qapi/schema: add static typing and assertions to lookup_type() |
|
Date: |
Wed, 15 Nov 2023 20:43:39 -0500 |
This function is a bit hard to type as-is; mypy needs some assertions to
assist with the type narrowing.
Signed-off-by: John Snow <jsnow@redhat.com>
---
scripts/qapi/schema.py | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
index a1094283828..3308f334872 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -968,8 +968,12 @@ def lookup_entity(self, name, typ=None):
return None
return ent
- def lookup_type(self, name):
- return self.lookup_entity(name, QAPISchemaType)
+ def lookup_type(self, name: str) -> Optional[QAPISchemaType]:
+ typ = self.lookup_entity(name, QAPISchemaType)
+ if typ is None:
+ return None
+ assert isinstance(typ, QAPISchemaType)
+ return typ
def resolve_type(self, name, info, what):
typ = self.lookup_type(name)
--
2.41.0
[PATCH 03/19] qapi/schema: name QAPISchemaInclude entities, John Snow, 2023/11/15
[PATCH 12/19] qapi/schema: split "checked" field into "checking" and "checked", John Snow, 2023/11/15