From 7a4feccf6474d658742b7b0fa8406d3a813c9023 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Mon, 19 Feb 2018 19:06:18 -0500 Subject: [PATCH] qapi: More idiomatic string operations Rather than slicing the end of a string, we can use python's endswith(). And rather than creating a set of characters, we can search for a character within a string. Backports commit 8712fa5333ad348da20034b717dd814219d1ec11 from qemu --- qemu/scripts/qapi.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qemu/scripts/qapi.py b/qemu/scripts/qapi.py index d706bdf5..77df6234 100644 --- a/qemu/scripts/qapi.py +++ b/qemu/scripts/qapi.py @@ -175,7 +175,7 @@ class QAPISchemaParser(object): if self.tok == '#': self.cursor = self.src.find('\n', self.cursor) - elif self.tok in ['{', '}', ':', ',', '[', ']']: + elif self.tok in "{}:,[]": return elif self.tok == "'": string = '' @@ -391,7 +391,7 @@ def add_name(name, info, meta, implicit=False): raise QAPIExprError(info, "%s '%s' is already defined" % (all_names[name], name)) - if not implicit and name[-4:] == 'Kind': + if not implicit and name.endswith('Kind'): raise QAPIExprError(info, "%s '%s' should not end in 'Kind'" % (meta, name)) @@ -910,7 +910,7 @@ class QAPISchemaEnumType(QAPISchemaType): def is_implicit(self): # See QAPISchema._make_implicit_enum_type() - return self.name[-4:] == 'Kind' + return self.name.endswith('Kind') def c_type(self, is_param=False): return c_name(self.name)