qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: John Snow <jsnow@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: Michael Roth <michael.roth@amd.com>,
	Cleber Rosa <crosa@redhat.com>,
	qemu-devel@nongnu.org, Eduardo Habkost <ehabkost@redhat.com>
Subject: Re: [PATCH v2 05/21] qapi/parser: Assert lexer value is a string
Date: Tue, 18 May 2021 11:19:25 -0400	[thread overview]
Message-ID: <504f3b32-67b8-4c20-bf82-f2d994ffe1b7@redhat.com> (raw)
In-Reply-To: <87lf8c5pid.fsf@dusky.pond.sub.org>

On 5/18/21 6:02 AM, Markus Armbruster wrote:
> John Snow <jsnow@redhat.com> writes:
> 
>> The type checker can't narrow the type of the token value to string,
>> because it's only loosely correlated with the return token.
>>
>> We know that a token of '#' should always have a "str" value.
>> Add an assertion.
>>
>> Signed-off-by: John Snow <jsnow@redhat.com>
>> ---
>>   scripts/qapi/parser.py | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
>> index d620706fffb..ba17f1357ad 100644
>> --- a/scripts/qapi/parser.py
>> +++ b/scripts/qapi/parser.py
>> @@ -304,6 +304,7 @@ def get_doc(self, info):
>>           cur_doc = QAPIDoc(self, info)
>>           self.accept(False)
>>           while self.tok == '#':
>> +            assert isinstance(self.val, str)  # comment token MUST have str val
> 
> What does the comment add to the assertion?  Isn't it all obvious?  Just
> wondering; if you genuinely think it isn't, I'm not going to argue.
> Except about the long line, which you could easily avoid:
> 

Yeah, I just suppose it's an artifact from when I was first reading this 
code. It wasn't necessarily obvious to me that comment tokens -- which 
are sometimes squelched -- must always have a str val that is non-None.

I felt like adding an assertion here required SOME kind of justification 
for WHY it was true. Since the val can be None *and* the lexer can omit 
comments, it seemed not expressly self-evident at the time.

Less obvious than, say, why 'tf' values will definitely be True/False. 
Maybe just my own brain bug.

I'm not as attached to it as other things at this point anymore, having 
spent more time in this file since I first wrote it.

Remove if you'd like. The commit message can perform the duty of 
explaining more deeply if people need.

>                 assert isinstance(self.val, str)  # comment value MUST be str
> 
>>               if self.val.startswith('##'):
>>                   # End of doc comment
>>                   if self.val != '##':





  reply	other threads:[~2021-05-18 15:33 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-11 22:05 [PATCH v2 00/21] qapi: static typing conversion, pt5a John Snow
2021-05-11 22:05 ` [PATCH v2 01/21] qapi/parser: Don't try to handle file errors John Snow
2021-05-18  9:28   ` Markus Armbruster
2021-05-18 13:14     ` John Snow
2021-05-19  7:01       ` Markus Armbruster
2021-05-19 17:17         ` John Snow
2021-05-19 17:51         ` John Snow
2021-05-18 19:01     ` John Snow
2021-05-19  6:51       ` Markus Armbruster
2021-05-11 22:05 ` [PATCH v2 02/21] qapi: Add test for nonexistent schema file John Snow
2021-05-11 22:05 ` [PATCH v2 03/21] qapi/source: Remove line number from QAPISourceInfo initializer John Snow
2021-05-11 22:05 ` [PATCH v2 04/21] qapi/parser: factor parsing routine into method John Snow
2021-05-18  9:57   ` Markus Armbruster
2021-05-18 15:11     ` John Snow
2021-05-11 22:05 ` [PATCH v2 05/21] qapi/parser: Assert lexer value is a string John Snow
2021-05-18 10:02   ` Markus Armbruster
2021-05-18 15:19     ` John Snow [this message]
2021-05-11 22:05 ` [PATCH v2 06/21] qapi/parser: enforce all top-level expressions must be dict in _parse() John Snow
2021-05-11 22:05 ` [PATCH v2 07/21] qapi/parser: assert object keys are strings John Snow
2021-05-11 22:05 ` [PATCH v2 08/21] qapi/parser: Use @staticmethod where appropriate John Snow
2021-05-11 22:05 ` [PATCH v2 09/21] qapi: add must_match helper John Snow
2021-05-11 22:05 ` [PATCH v2 10/21] qapi/parser: Fix token membership tests when token can be None John Snow
2021-05-11 22:05 ` [PATCH v2 11/21] qapi/parser: Rework _check_pragma_list_of_str as a TypeGuard John Snow
2021-05-11 22:05 ` [PATCH v2 12/21] qapi/parser: add type hint annotations John Snow
2021-05-18 12:01   ` Markus Armbruster
2021-05-18 13:25     ` John Snow
2021-05-11 22:05 ` [PATCH v2 13/21] qapi/parser: Remove superfluous list comprehension John Snow
2021-05-11 22:05 ` [PATCH v2 14/21] qapi/parser: allow 'ch' variable name John Snow
2021-05-11 22:05 ` [PATCH v2 15/21] qapi/parser: add docstrings John Snow
2021-05-19  6:41   ` Markus Armbruster
2021-05-19 18:21     ` John Snow
2021-05-11 22:05 ` [PATCH v2 16/21] CHECKPOINT John Snow
2021-05-11 22:05 ` [PATCH v2 17/21] qapi: [WIP] Rip QAPIDoc out of parser.py John Snow
2021-05-11 22:05 ` [PATCH v2 18/21] qapi: [WIP] Add type ignores for qapidoc.py John Snow
2021-05-11 22:05 ` [PATCH v2 19/21] qapi: [WIP] Import QAPIDoc from qapidoc Signed-off-by: John Snow <jsnow@redhat.com> John Snow
2021-05-11 22:06 ` [PATCH v2 20/21] qapi: [WIP] Add QAPIDocError John Snow
2021-05-11 22:06 ` [PATCH v2 21/21] qapi: [WIP] Enable linters on parser.py John Snow

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=504f3b32-67b8-4c20-bf82-f2d994ffe1b7@redhat.com \
    --to=jsnow@redhat.com \
    --cc=armbru@redhat.com \
    --cc=crosa@redhat.com \
    --cc=ehabkost@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).