[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v4 11/14] qapi/introspect.py: add type hint annotations
From: |
Markus Armbruster |
Subject: |
Re: [PATCH v4 11/14] qapi/introspect.py: add type hint annotations |
Date: |
Wed, 03 Feb 2021 16:15:05 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) |
John Snow <jsnow@redhat.com> writes:
> Signed-off-by: John Snow <jsnow@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.
[...]
- Re: [PATCH v4 08/14] qapi/introspect.py: create a typed 'Annotated' data strutcure, (continued)
- Re: [PATCH v4 08/14] qapi/introspect.py: create a typed 'Annotated' data strutcure, Eduardo Habkost, 2021/02/03
- Re: [PATCH v4 08/14] qapi/introspect.py: create a typed 'Annotated' data strutcure, Markus Armbruster, 2021/02/04
- Re: [PATCH v4 08/14] qapi/introspect.py: create a typed 'Annotated' data strutcure, John Snow, 2021/02/04
- Re: [PATCH v4 08/14] qapi/introspect.py: create a typed 'Annotated' data strutcure, Eduardo Habkost, 2021/02/04
- Re: [PATCH v4 08/14] qapi/introspect.py: create a typed 'Annotated' data strutcure, Markus Armbruster, 2021/02/05
- Re: [PATCH v4 08/14] qapi/introspect.py: create a typed 'Annotated' data strutcure, John Snow, 2021/02/03
- Re: [PATCH v4 08/14] qapi/introspect.py: create a typed 'Annotated' data strutcure, Markus Armbruster, 2021/02/05
[PATCH v4 10/14] qapi/introspect.py: improve readability of _tree_to_qlit, John Snow, 2021/02/02
[PATCH v4 09/14] qapi/introspect.py: improve _tree_to_qlit error message, John Snow, 2021/02/02
[PATCH v4 11/14] qapi/introspect.py: add type hint annotations, John Snow, 2021/02/02
- Re: [PATCH v4 11/14] qapi/introspect.py: add type hint annotations,
Markus Armbruster <=
- Re: [PATCH v4 11/14] qapi/introspect.py: add type hint annotations, John Snow, 2021/02/03
- Re: [PATCH v4 11/14] qapi/introspect.py: add type hint annotations, Markus Armbruster, 2021/02/05
- Re: [PATCH v4 11/14] qapi/introspect.py: add type hint annotations, John Snow, 2021/02/08
- Re: [PATCH v4 11/14] qapi/introspect.py: add type hint annotations, John Snow, 2021/02/08
- Re: [PATCH v4 11/14] qapi/introspect.py: add type hint annotations, Markus Armbruster, 2021/02/09
- Re: [PATCH v4 11/14] qapi/introspect.py: add type hint annotations, John Snow, 2021/02/10
[PATCH v4 12/14] qapi/introspect.py: add introspect.json dummy types, John Snow, 2021/02/02
[PATCH v4 14/14] qapi/introspect.py: Update copyright and authors list, John Snow, 2021/02/02
[PATCH v4 13/14] qapi/introspect.py: Add docstring to _tree_to_qlit, John Snow, 2021/02/02