All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Snow <jsnow@redhat.com>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: "Michael Roth" <michael.roth@amd.com>,
	"Cleber Rosa" <crosa@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	qemu-devel@nongnu.org
Subject: Re: [PATCH v2 07/12] qapi/schema: make QAPISourceInfo mandatory
Date: Wed, 13 Jan 2021 19:47:17 -0500	[thread overview]
Message-ID: <a04a9b76-7df3-c9ad-38d4-170942a5064c@redhat.com> (raw)
In-Reply-To: <20210114002944.GI4161@habkost.net>

On 1/13/21 7:29 PM, Eduardo Habkost wrote:
> On Wed, Jan 13, 2021 at 06:04:29PM -0500, John Snow wrote:
>> On 1/13/21 11:12 AM, Markus Armbruster wrote:
>>> John Snow <jsnow@redhat.com> writes:

...

>>
>> I think we need to, yes; or we probably really, really want to. Making the
>> info parameter optional really adds a lot of unidiomatic type-checking
>> confetti when we go to use info, and in many more contexts than just this
>> sorta-built-in-enum; it will creep badly.
> 
> Which methods would require unidiomatic type-checking because of
> None/Optional?
> 

Virtually everything that accepts a QAPISourceInfo has to do something 
like this:

def foo(info: Optional[QAPISourceInfo]):
     if info is None:
         raise Exception("Something very bad has happened!")
     ...
     ...


Since the great majority of cases *will* have an info, and we take 
careful pains to make sure this info is preserved, it's less invasive to 
just assert that info isn't Optional.

This is especially true for the QAPISchemaMember initializer, which 
several other classes inherit -- if this is allowed to be 
Optional[QAPISourceInfo], any and all users of a QAPISchemaMember or any 
derived classes will have to check -- on every access -- to see if 
'member.info' is set or not.

Since we expect it to be set 100% of the time for all user-defined code, 
it's a lot less "if member.info is not None" checks everywhere.

Adding a special "built-in" source info object to make this claim helps 
avoid making confusing type signatures for the visitors; i.e.

def visit_thing(info: Optional[QAPISourceInfo]): ...

is misleading, because we actually expect thing to *always* have a 
SourceInfo. To make the documentation be a little more ... statistically 
truthful, it's easier to bend the rules in the other direction and just 
fill in the scant few cases where we don't have a QAPISourceInfo.

--js



  reply	other threads:[~2021-01-14  0:48 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-17  1:59 [PATCH v2 00/12] qapi: static typing conversion, pt1.5 John Snow
2020-12-17  1:59 ` [PATCH v2 01/12] qapi/commands: assert arg_type is not None John Snow
2020-12-17  1:59 ` [PATCH v2 02/12] qapi/events: fix visit_event typing John Snow
2020-12-17  1:59 ` [PATCH v2 03/12] qapi/main: handle theoretical None-return from re.match() John Snow
2020-12-17  1:59 ` [PATCH v2 04/12] qapi/gen: assert that _start_if is not None in _wrap_ifcond John Snow
2021-01-13 15:14   ` Markus Armbruster
2021-01-13 21:34     ` John Snow
2020-12-17  1:59 ` [PATCH v2 05/12] qapi/gen: use './builtin' for the built-in module name John Snow
2020-12-17  1:59 ` [PATCH v2 06/12] qapi/source: Add builtin null-object sentinel John Snow
2021-01-13 15:39   ` Markus Armbruster
2021-01-13 22:30     ` John Snow
2021-01-14 13:39       ` Markus Armbruster
2021-01-18 18:36         ` Eduardo Habkost
2021-01-19 10:21           ` Markus Armbruster
2021-01-19 16:10             ` Eduardo Habkost
2020-12-17  1:59 ` [PATCH v2 07/12] qapi/schema: make QAPISourceInfo mandatory John Snow
2021-01-13 16:12   ` Markus Armbruster
2021-01-13 23:04     ` John Snow
2021-01-14  0:29       ` Eduardo Habkost
2021-01-14  0:47         ` John Snow [this message]
2020-12-17  1:59 ` [PATCH v2 08/12] qapi/gen: write _genc/_genh access shims John Snow
2020-12-17  1:59 ` [PATCH v2 09/12] qapi/gen: move write method to QAPIGenC, make fname a str John Snow
2020-12-17  1:59 ` [PATCH v2 10/12] tests/qapi-schema: Add quotes to module name in test output John Snow
2020-12-17  1:59 ` [PATCH v2 11/12] qapi/schema: Name the builtin module "" instead of None John Snow
2020-12-17  1:59 ` [PATCH v2 12/12] qapi: enable strict-optional checks John Snow
2021-01-13 16:23 ` [PATCH v2 00/12] qapi: static typing conversion, pt1.5 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=a04a9b76-7df3-c9ad-38d4-170942a5064c@redhat.com \
    --to=jsnow@redhat.com \
    --cc=armbru@redhat.com \
    --cc=crosa@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=marcandre.lureau@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.