John Snow <js...@redhat.com> writes: > Signed-off-by: John Snow <js...@redhat.com> > --- > scripts/qapi/introspect.py | 115 ++++++++++++++++++++++++++----------- > scripts/qapi/mypy.ini | 5 -- > scripts/qapi/schema.py | 2 +- > 3 files changed, 82 insertions(+), 40 deletions(-) > > diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py > index 60ec326d2c7..b7f2a6cf260 100644 > --- a/scripts/qapi/introspect.py > +++ b/scripts/qapi/introspect.py > @@ -30,10 +30,19 @@ > ) > from .gen import QAPISchemaMonolithicCVisitor > from .schema import ( > + QAPISchema, > QAPISchemaArrayType, > QAPISchemaBuiltinType, > + QAPISchemaEntity, > + QAPISchemaEnumMember, > + QAPISchemaFeature, > + QAPISchemaObjectType, > + QAPISchemaObjectTypeMember, > QAPISchemaType, > + QAPISchemaVariant, > + QAPISchemaVariants, > ) > +from .source import QAPISourceInfo > > > # This module constructs a tree data structure that is used to > @@ -57,6 +66,8 @@ # generate the introspection information for QEMU. It behaves similarly # to a JSON value. # # A complexity over JSON is that our values may or may not be annotated. # # Un-annotated values may be: # Scalar: str, bool, None. # Non-scalar: List, Dict # _value = Union[str, bool, None, Dict[str, TreeValue], List[TreeValue]] # # With optional annotations, the type of all values is: # TreeValue = Union[_value, Annotated[_value]] # # Sadly, mypy does not support recursive types, so we must approximate this. _stub = Any _scalar = Union[str, bool, None] _nonscalar = Union[Dict[str, _stub], List[_stub]] > _value = Union[_scalar, _nonscalar] > TreeValue = Union[_value, 'Annotated[_value]'] > > +# This is a (strict) alias for an arbitrary object non-scalar, as above: > +_DObject = Dict[str, object]
Sounds greek :) It's almost the Dict part of _nonscalar, but not quite: object vs. Any. I naively expect something closer to _scalar = ... _object = Dict[str, _stub] _nonscalar = Union[_object, List[_stub] and (still naively) expect _object to be good enough to serve as type annotation for dicts representing JSON objects. [...]