[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 11/19] qapi/expr.py: Modify check_keys to accept any Collectio
From: |
John Snow |
Subject: |
[PATCH v4 11/19] qapi/expr.py: Modify check_keys to accept any Collection |
Date: |
Thu, 25 Mar 2021 02:03:48 -0400 |
This is a minor adjustment that allows the 'required' and 'optional'
keys fields to take a default value of an empty, immutable sequence (the
empty tuple).
This reveals a quirk of this function, which is that "a + b" is
list-specific behavior. We can accept a wider variety of types if we
avoid that behavior. Using Collection allows us to accept things like
lists, tuples, sets, and so on.
(Iterable would also have worked, but Iterable also includes things like
generator expressions which are consumed upon iteration, which would
require a rewrite to make sure that each input was only traversed once.)
Signed-off-by: John Snow <jsnow@redhat.com>
---
scripts/qapi/expr.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py
index 505e67bd21..7e22723b50 100644
--- a/scripts/qapi/expr.py
+++ b/scripts/qapi/expr.py
@@ -100,7 +100,7 @@ def pprint(elems):
"%s misses key%s %s"
% (source, 's' if len(missing) > 1 else '',
pprint(missing)))
- allowed = set(required + optional)
+ allowed = set(required) | set(optional)
unknown = set(value) - allowed
if unknown:
raise QAPISemError(
--
2.30.2
- [PATCH v4 12/19] qapi/expr.py: add type hint annotations, (continued)
- [PATCH v4 12/19] qapi/expr.py: add type hint annotations, John Snow, 2021/03/25
- [PATCH v4 13/19] qapi/expr.py: Consolidate check_if_str calls in check_if, John Snow, 2021/03/25
- [PATCH v4 15/19] qapi/expr.py: enable pylint checks, John Snow, 2021/03/25
- [PATCH v4 17/19] qapi/expr.py: Use tuples instead of lists for static data, John Snow, 2021/03/25
- [PATCH v4 16/19] qapi/expr.py: Add docstrings, John Snow, 2021/03/25
- [PATCH v4 18/19] qapi/expr.py: move related checks inside check_xxx functions, John Snow, 2021/03/25
- [PATCH v4 14/19] qapi/expr.py: Remove single-letter variable, John Snow, 2021/03/25
- [PATCH v4 11/19] qapi/expr.py: Modify check_keys to accept any Collection,
John Snow <=
- [PATCH v4 19/19] qapi/expr.py: Use an expression checker dispatch table, John Snow, 2021/03/25
- Re: [PATCH v4 00/19] qapi: static typing conversion, pt3, Markus Armbruster, 2021/03/25
- Re: [PATCH v4 00/19] qapi: static typing conversion, pt3, John Snow, 2021/03/25
- Re: [PATCH v4 00/19] qapi: static typing conversion, pt3, John Snow, 2021/03/26