Skip to content

Commit

Permalink
qapi: Dumb down QAPISchema.lookup_entity()
Browse files Browse the repository at this point in the history
QAPISchema.lookup_entity() takes an optional type argument, a subtype
of QAPISchemaDefinition, and returns that type or None.  Callers can
use this to save themselves an isinstance() test.

The only remaining user of this convenience feature is .lookup_type().
But we don't actually save anything anymore there: we still need the
isinstance() to help mypy over the hump.

Drop the .lookup_entity() argument, and adjust .lookup_type().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20240315152301.3621858-26-armbru@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
[Commit message typo fixed]
  • Loading branch information
Markus Armbruster committed Apr 24, 2024
1 parent 99e75d8 commit 060b5a9
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions scripts/qapi/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1157,20 +1157,14 @@ def _def_definition(self, defn: QAPISchemaDefinition) -> None:
defn.info, "%s is already defined" % other_defn.describe())
self._entity_dict[defn.name] = defn

def lookup_entity(
self,
name: str,
typ: Optional[type] = None,
) -> Optional[QAPISchemaDefinition]:
ent = self._entity_dict.get(name)
if typ and not isinstance(ent, typ):
return None
return ent
def lookup_entity(self,name: str) -> Optional[QAPISchemaEntity]:
return self._entity_dict.get(name)

def lookup_type(self, name: str) -> Optional[QAPISchemaType]:
typ = self.lookup_entity(name, QAPISchemaType)
assert typ is None or isinstance(typ, QAPISchemaType)
return typ
typ = self.lookup_entity(name)
if isinstance(typ, QAPISchemaType):
return typ
return None

def resolve_type(
self,
Expand Down

0 comments on commit 060b5a9

Please sign in to comment.