[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 09/11] qapi/introspect.py: create a typed 'Annotated' data
|
From: |
Cleber Rosa |
|
Subject: |
Re: [PATCH v2 09/11] qapi/introspect.py: create a typed 'Annotated' data strutcure |
|
Date: |
Sat, 7 Nov 2020 00:45:22 -0500 |
On Mon, Oct 26, 2020 at 03:42:49PM -0400, John Snow wrote:
> This replaces _make_tree with Annotated(). By creating it as a generic
> container, we can more accurately describe the exact nature of this
> particular value. i.e., each Annotated object is actually an
> Annotated<T>, describing its contained value.
>
> This adds stricter typing to Annotated nodes and extra annotated
> information. It also replaces a check of "isinstance tuple" with the
> much more explicit "isinstance Annotated" which is guaranteed not to
> break if a tuple is accidentally introduced into the type tree. (Perhaps
> as a result of a bad conversion from a list.)
>
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
> scripts/qapi/introspect.py | 97 +++++++++++++++++++-------------------
> 1 file changed, 48 insertions(+), 49 deletions(-)
>
> diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py
> index a0978cb3adb..a261e402d69 100644
> --- a/scripts/qapi/introspect.py
> +++ b/scripts/qapi/introspect.py
> @@ -13,12 +13,13 @@
> from typing import (
> Any,
> Dict,
> + Generic,
> + Iterable,
> List,
> Optional,
> Sequence,
> - Tuple,
> + TypeVar,
> Union,
> - cast,
> )
>
> from .common import (
> @@ -63,50 +64,48 @@
> _scalar = Union[str, bool, None]
> _nonscalar = Union[Dict[str, _stub], List[_stub]]
> _value = Union[_scalar, _nonscalar]
> -TreeValue = Union[_value, 'Annotated']
> +TreeValue = Union[_value, 'Annotated[_value]']
>
> # This is just an alias for an object in the structure described above:
> _DObject = Dict[str, object]
>
> -# Represents the annotations themselves:
> -Annotations = Dict[str, object]
>
> -# Represents an annotated node (of some kind).
> -Annotated = Tuple[_value, Annotations]
> +_AnnoType = TypeVar('_AnnoType', bound=TreeValue)
Here it becomes much harder to keep the suggestions I made on patch
5 because of forward and backward references.
Reviewed-by: Cleber Rosa <crosa@redhat.com>
signature.asc
Description: PGP signature
- Re: [PATCH v2 09/11] qapi/introspect.py: create a typed 'Annotated' data strutcure,
Cleber Rosa <=