[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/5] qapi: Drop Indentation.__bool__()
From: |
Markus Armbruster |
Subject: |
[PATCH 2/5] qapi: Drop Indentation.__bool__() |
Date: |
Wed, 8 Sep 2021 06:54:25 +0200 |
Intentation.__bool__() is not worth its keep: it has just one user,
which can just as well check .__str__() instead.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
scripts/qapi/common.py | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index c4d11b9637..1d62c27fb7 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -142,10 +142,6 @@ def __str__(self) -> str:
"""Return the current indentation as a string of spaces."""
return ' ' * self._level
- def __bool__(self) -> bool:
- """True when there is a non-zero indentation."""
- return bool(self._level)
-
def increase(self, amount: int = 4) -> None:
"""Increase the indentation level by ``amount``, default 4."""
self._level += amount
@@ -169,8 +165,9 @@ def cgen(code: str, **kwds: object) -> str:
Obey `indent`, and strip `EATSPACE`.
"""
raw = code % kwds
- if indent:
- raw = re.sub(r'^(?!(#|$))', str(indent), raw, flags=re.MULTILINE)
+ pfx = str(indent)
+ if pfx:
+ raw = re.sub(r'^(?!(#|$))', pfx, raw, flags=re.MULTILINE)
return re.sub(re.escape(EATSPACE) + r' *', '', raw)
--
2.31.1
- [PATCH 0/5] qapi: Another round of minor fixes and cleanups, Markus Armbruster, 2021/09/08
- [PATCH 4/5] tests/qapi-schema: Cover 'not' condition with empty argument, Markus Armbruster, 2021/09/08
- [PATCH 3/5] qapi: Bury some unused code in class Indentation, Markus Armbruster, 2021/09/08
- [PATCH 5/5] qapi: Fix bogus error for 'if': { 'not': '' }, Markus Armbruster, 2021/09/08
- [PATCH 1/5] qapi: Fix a botched type annotation, Markus Armbruster, 2021/09/08
- [PATCH 2/5] qapi: Drop Indentation.__bool__(),
Markus Armbruster <=
- Re: [PATCH 0/5] qapi: Another round of minor fixes and cleanups, Marc-André Lureau, 2021/09/08
- Re: [PATCH 0/5] qapi: Another round of minor fixes and cleanups, Markus Armbruster, 2021/09/13