[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 10/22] qapi/parser: Fix typing of token membership tests
From: |
Markus Armbruster |
Subject: |
Re: [PATCH 10/22] qapi/parser: Fix typing of token membership tests |
Date: |
Sun, 25 Apr 2021 09:59:16 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) |
John Snow <jsnow@redhat.com> writes:
> When the token can be None, we can't use 'x in "abc"' style membership
> tests to group types of tokens together, because 'None in "abc"' is a
> TypeError.
>
> Easy enough to fix, if not a little ugly.
>
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
> scripts/qapi/parser.py | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
> index 7f3c009f64b..16fd36f8391 100644
> --- a/scripts/qapi/parser.py
> +++ b/scripts/qapi/parser.py
> @@ -272,7 +272,7 @@ def get_values(self):
> if self.tok == ']':
> self.accept()
> return expr
> - if self.tok not in "{['tf":
> + if self.tok is None or self.tok not in "{['tf":
> raise QAPIParseError(
> self, "expected '{', '[', ']', string, or boolean")
> while True:
> @@ -294,7 +294,8 @@ def get_expr(self, nested):
> elif self.tok == '[':
> self.accept()
> expr = self.get_values()
> - elif self.tok in "'tf":
> + elif self.tok and self.tok in "'tf":
> + assert isinstance(self.val, (str, bool))
> expr = self.val
> self.accept()
> else:
How can self.tok be None?
I suspect this is an artifact of PATCH 04. Before, self.tok is
initialized to the first token, then set to subsequent tokens (all str)
in turn. After, it's initialized to None, then set to tokens in turn.
- Re: [PATCH 12/22] qapi/parser: add type hint annotations, (continued)
- [PATCH 02/22] qapi/source: [RFC] add "with_column" contextmanager, John Snow, 2021/04/21
- [PATCH 11/22] qapi/parser: Rework _check_pragma_list_of_str as a TypeGuard, John Snow, 2021/04/21
- [PATCH 15/22] qapi/parser: allow 'ch' variable name, John Snow, 2021/04/21
- [PATCH 16/22] qapi/parser: add docstrings, John Snow, 2021/04/21
- [PATCH 10/22] qapi/parser: Fix typing of token membership tests, John Snow, 2021/04/21
- Re: [PATCH 10/22] qapi/parser: Fix typing of token membership tests,
Markus Armbruster <=
- [PATCH 14/22] qapi/parser: Remove superfluous list constructor, John Snow, 2021/04/21
- [PATCH 17/22] CHECKPOINT, John Snow, 2021/04/21
- [PATCH 19/22] qapi: [WIP] Add type ignores for qapidoc.py, John Snow, 2021/04/21
- [PATCH 20/22] qapi: [WIP] Import QAPIDoc from qapidoc Signed-off-by: John Snow <address@hidden>, John Snow, 2021/04/21
- [PATCH 22/22] qapi: [WIP] Enable linters on parser.py, John Snow, 2021/04/21
- [PATCH 21/22] qapi: [WIP] Add QAPIDocError, John Snow, 2021/04/21
- [PATCH 13/22] qapi/parser: [RFC] overload the return type of get_expr, John Snow, 2021/04/21
- [PATCH 18/22] qapi: [WIP] Rip QAPIDoc out of parser.py, John Snow, 2021/04/21