From: Markus Armbruster <armbru@redhat.com>
To: John Snow <jsnow@redhat.com>
Cc: qemu-devel@nongnu.org, Eduardo Habkost <ehabkost@redhat.com>,
Cleber Rosa <crosa@redhat.com>
Subject: Re: [PATCH v2 09/11] qapi/introspect.py: create a typed 'Annotated' data strutcure
Date: Wed, 16 Dec 2020 08:08:53 +0100 [thread overview]
Message-ID: <87bleuw7lm.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <b27f7930-d86b-8357-84e4-7daef00023d7@redhat.com> (John Snow's message of "Mon, 7 Dec 2020 19:21:26 -0500")
John Snow <jsnow@redhat.com> writes:
> On 11/16/20 5:12 AM, Markus Armbruster wrote:
>> John Snow <jsnow@redhat.com> writes:
>>
>>> 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.
>>
>> Inhowfar?
>>
>
> The Generic[T] trick lets us express the type of the annotated node
> itself, which is more specific than Tuple[_something, ...etc...] and
> this type can be preserved when we peel the annotations off.
>
> It's not super crucial, but like you say, the big benefit is the field
> names and strict types for the special-purpose structure.
I'd lead with a brief description of the data structure you're
replacing, how we got there, and why it's ugly. You can steal from my
review of PATCH 5. Then explain its replacement, briefly. And only
then talk about types.
By the time you get to types, I'm nodding along "yes, please", and will
be predisposed to accept your typing arguments at face value.
If you start with typing arguments, they have to negotiate the "yes,
please" bar all by themselves. Harder, because Python typing stuff you
have to explain for dummies.
>>> 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.)
>>
>> Sure this is worth writing home about? Such accidents seem quite
>> unlikely.
>>
>
> We all have our phobias. I find "isinstance(x,
> extremely_common_stdlib_type)" to be extremely fragile and likely to
> frustrate.
You're applying programming-in-the-large reasoning to a
programming-in-the-small case.
Say you're writing a piece of code you expect to be used in contexts you
prudently refuse to predict. The code deals with a bunch of basic
Python types. Reserving another basic Python type for internal use may
well be unwise then, because it can make your code break confusingly
when this other type appears in input. Which it shouldn't, but making
your reusable code harder to misuse, and misuses easier to diagnose are
laudable goals.
This is not such a piece of code. All the users it will ever have are
in the same file of 200-something LOC.
Your commit message makes the case for your patch. Sometimes, dropping
weak arguments strengthens a case. I believe dropping the "It also
replaces" argument would strengthen your case.
> Maybe what's unlikely is anyone editing this code ever again. You've
> mentioned wanting to look into changing how the schema information is
> stored in QEMU before, so a lot of this might not matter for too much
> longer, who knows.
Yes, I expect generating the SchemaInfoList directly would beat
generating QLitObject, then converting QLitObject -> QObject ->
SchemaInfoList. Whether it's worth the effort is unclear.
>> For me, the commit's benefit is making the structure of the annotated
>> tree node more explicit (your first paragraph, I guess). It's a bit of
>> a pattern in developing Python code: we start with a Tuple because it's
>> terse and easy, then things get more complex, terse becomes too terse,
>> and we're replacing the Tuple with a class.
>>
>
> Yep.
>
>>> Signed-off-by: John Snow <jsnow@redhat.com>
next prev parent reply other threads:[~2020-12-16 7:10 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-26 19:42 [PATCH v2 00/11] qapi: static typing conversion, pt2 John Snow
2020-10-26 19:42 ` [PATCH v2 01/11] [DO-NOT-MERGE] docs: replace single backtick (`) with double-backtick (``) John Snow
2020-10-26 19:42 ` [PATCH v2 02/11] [DO-NOT-MERGE] docs/sphinx: change default role to "any" John Snow
2020-10-26 19:42 ` [PATCH v2 03/11] [DO-NOT-MERGE] docs: enable sphinx-autodoc for scripts/qapi John Snow
2020-10-26 19:42 ` [PATCH v2 04/11] qapi/introspect.py: add assertions and casts John Snow
2020-11-06 18:59 ` Cleber Rosa
2020-10-26 19:42 ` [PATCH v2 05/11] qapi/introspect.py: add preliminary type hint annotations John Snow
2020-11-07 2:12 ` Cleber Rosa
2020-12-07 21:29 ` John Snow
2020-11-13 16:48 ` Markus Armbruster
2020-12-07 23:48 ` John Snow
2020-12-16 7:51 ` Markus Armbruster
2020-12-16 17:49 ` Eduardo Habkost
2020-12-17 6:51 ` Markus Armbruster
2020-12-17 1:35 ` John Snow
2020-12-17 7:00 ` Markus Armbruster
2020-10-26 19:42 ` [PATCH v2 06/11] qapi/introspect.py: add _gen_features helper John Snow
2020-11-07 4:23 ` Cleber Rosa
2020-11-16 8:47 ` Markus Armbruster
2020-12-07 23:57 ` John Snow
2020-12-15 16:55 ` Markus Armbruster
2020-12-15 18:49 ` John Snow
2020-10-26 19:42 ` [PATCH v2 07/11] qapi/introspect.py: Unify return type of _make_tree() John Snow
2020-11-07 5:08 ` Cleber Rosa
2020-12-15 0:22 ` John Snow
2020-11-16 9:46 ` Markus Armbruster
2020-12-08 0:06 ` John Snow
2020-12-16 6:35 ` Markus Armbruster
2020-10-26 19:42 ` [PATCH v2 08/11] qapi/introspect.py: replace 'extra' dict with 'comment' argument John Snow
2020-11-07 5:10 ` Cleber Rosa
2020-11-16 9:55 ` Markus Armbruster
2020-12-08 0:12 ` John Snow
2020-10-26 19:42 ` [PATCH v2 09/11] qapi/introspect.py: create a typed 'Annotated' data strutcure John Snow
2020-11-07 5:45 ` Cleber Rosa
2020-11-16 10:12 ` Markus Armbruster
2020-12-08 0:21 ` John Snow
2020-12-16 7:08 ` Markus Armbruster [this message]
2020-12-17 1:30 ` John Snow
2020-10-26 19:42 ` [PATCH v2 10/11] qapi/introspect.py: improve readability of _tree_to_qlit John Snow
2020-11-07 5:54 ` Cleber Rosa
2020-11-16 10:17 ` Markus Armbruster
2020-12-15 15:25 ` John Snow
2020-10-26 19:42 ` [PATCH v2 11/11] qapi/introspect.py: Add docstring to _tree_to_qlit John Snow
2020-11-07 5:57 ` Cleber Rosa
2020-11-02 15:40 ` [PATCH v2 00/11] qapi: static typing conversion, pt2 John Snow
2020-11-04 9:51 ` Marc-André Lureau
2020-12-15 15:52 ` John Snow
2020-11-16 13:17 ` introspect.py output representation (was: [PATCH v2 00/11] qapi: static typing conversion, pt2) 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=87bleuw7lm.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=crosa@redhat.com \
--cc=ehabkost@redhat.com \
--cc=jsnow@redhat.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.