[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 05/21] qapi/parser: Assert lexer value is a string
From: |
Markus Armbruster |
Subject: |
Re: [PATCH v2 05/21] qapi/parser: Assert lexer value is a string |
Date: |
Tue, 18 May 2021 12:02:02 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) |
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:
assert isinstance(self.val, str) # comment value MUST be str
> if self.val.startswith('##'):
> # End of doc comment
> if self.val != '##':
- [PATCH v2 00/21] qapi: static typing conversion, pt5a, John Snow, 2021/05/11
- [PATCH v2 01/21] qapi/parser: Don't try to handle file errors, John Snow, 2021/05/11
- [PATCH v2 06/21] qapi/parser: enforce all top-level expressions must be dict in _parse(), John Snow, 2021/05/11
- [PATCH v2 02/21] qapi: Add test for nonexistent schema file, John Snow, 2021/05/11
- [PATCH v2 03/21] qapi/source: Remove line number from QAPISourceInfo initializer, John Snow, 2021/05/11
- [PATCH v2 07/21] qapi/parser: assert object keys are strings, John Snow, 2021/05/11
- [PATCH v2 05/21] qapi/parser: Assert lexer value is a string, John Snow, 2021/05/11
- Re: [PATCH v2 05/21] qapi/parser: Assert lexer value is a string,
Markus Armbruster <=
- [PATCH v2 04/21] qapi/parser: factor parsing routine into method, John Snow, 2021/05/11
- [PATCH v2 09/21] qapi: add must_match helper, John Snow, 2021/05/11
- [PATCH v2 08/21] qapi/parser: Use @staticmethod where appropriate, John Snow, 2021/05/11
- [PATCH v2 10/21] qapi/parser: Fix token membership tests when token can be None, John Snow, 2021/05/11
- [PATCH v2 11/21] qapi/parser: Rework _check_pragma_list_of_str as a TypeGuard, John Snow, 2021/05/11
- [PATCH v2 12/21] qapi/parser: add type hint annotations, John Snow, 2021/05/11