All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: John Snow <jsnow@redhat.com>
Cc: qemu-devel@nongnu.org,  Michael Roth <michael.roth@amd.com>
Subject: Re: [PATCH v4 4/6] qapi/parser: add QAPIExpression type
Date: Wed, 15 Feb 2023 10:43:13 +0100	[thread overview]
Message-ID: <87v8k3clhq.fsf@pond.sub.org> (raw)
In-Reply-To: <20230215000011.1725012-5-jsnow@redhat.com> (John Snow's message of "Tue, 14 Feb 2023 19:00:09 -0500")

John Snow <jsnow@redhat.com> writes:

> This patch creates a new type, QAPIExpression, which represents a parsed
> expression complete with QAPIDoc and QAPISourceInfo.
>
> This patch turns parser.exprs into a list of QAPIExpression instead,
> and adjusts expr.py to match.
>
> This allows the types we specify in parser.py to be "remembered" all the
> way through expr.py and into schema.py. Several assertions around
> packing and unpacking this data can be removed as a result.

Suggest to add:

  It also corrects a harmless typing error.  Before the patch,
  check_exprs() allegedly takes a List[_JSONObject].  It actually takes
  a list of dicts of the form

      {'expr': E, 'info': I, 'doc': D}

  where E is of type _ExprValue, I is of type QAPISourceInfo, and D is
  of type QAPIDoc.  Key 'doc' is optional.  This is not a _JSONObject!
  Passes type checking anyway, because _JSONObject is Dict[str, object].

> Signed-off-by: John Snow <jsnow@redhat.com>

[...]

> diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
> index 1b006cdc133..50906e27d49 100644
> --- a/scripts/qapi/parser.py
> +++ b/scripts/qapi/parser.py
> @@ -21,6 +21,7 @@
>      TYPE_CHECKING,
>      Dict,
>      List,
> +    Mapping,
>      Optional,
>      Set,
>      Union,
> @@ -37,15 +38,24 @@
>      from .schema import QAPISchemaFeature, QAPISchemaMember
>  
>  
> -#: Represents a single Top Level QAPI schema expression.
> -TopLevelExpr = Dict[str, object]
> -
>  # Return value alias for get_expr().
>  _ExprValue = Union[List[object], Dict[str, object], str, bool]
>  
> -# FIXME: Consolidate and centralize definitions for TopLevelExpr,
> -# _ExprValue, _JSONValue, and _JSONObject; currently scattered across
> -# several modules.
> +
> +# FIXME: Consolidate and centralize definitions for _ExprValue,
> +# JSONValue, and _JSONObject; currently scattered across several
> +# modules.
> +
> +
> +class QAPIExpression(Dict[str, object]):
> +    # pylint: disable=too-few-public-methods
> +    def __init__(self,
> +                 data: Mapping[str, object],

Would @expr be a better name?

> +                 info: QAPISourceInfo,
> +                 doc: Optional['QAPIDoc'] = None):
> +        super().__init__(data)
> +        self.info = info
> +        self.doc: Optional['QAPIDoc'] = doc
>  
>  
>  class QAPIParseError(QAPISourceError):

[...]

Regardless,
Reviewed-by: Markus Armbruster <armbru@redhat.com>



  reply	other threads:[~2023-02-15  9:43 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-15  0:00 [PATCH v4 0/6] qapi: static typing conversion, pt5c John Snow
2023-02-15  0:00 ` [PATCH v4 1/6] qapi: Update flake8 config John Snow
2023-02-15  0:00 ` [PATCH v4 2/6] qapi: update pylint configuration John Snow
2023-02-15  0:00 ` [PATCH v4 3/6] qapi: Add minor typing workaround for 3.6 John Snow
2023-02-15  7:15   ` Markus Armbruster
2023-02-15 13:36     ` Markus Armbruster
2023-02-15 14:46       ` John Snow
2023-02-15  0:00 ` [PATCH v4 4/6] qapi/parser: add QAPIExpression type John Snow
2023-02-15  9:43   ` Markus Armbruster [this message]
2023-02-15 19:05     ` John Snow
2023-02-15  0:00 ` [PATCH v4 5/6] qapi: remove _JSONObject John Snow
2023-02-15  9:44   ` Markus Armbruster
2023-02-15  0:00 ` [PATCH v4 6/6] qapi: remove JSON value FIXME John Snow
2023-02-15 11:13   ` Markus Armbruster
2023-02-15 13:39 ` [PATCH v4 0/6] qapi: static typing conversion, pt5c Markus Armbruster
2023-02-21  1:26   ` John Snow
2023-02-21  6:42     ` Markus Armbruster
2023-02-21 17:32       ` John Snow
2023-02-22  9:16         ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87v8k3clhq.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=michael.roth@amd.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.