Thread (2 messages) 2 messages, 2 authors, 2021-07-30

Re: [PATCH] rteval: Add __contains__ in rtevalConfig

From: Atsushi Nemoto <hidden>
Date: 2021-07-30 05:03:22

On Thu, 29 Jul 2021 23:05:40 -0400, John Kacur [off-list ref] wrote:
quoted hunk ↗ jump to hunk
Add the __contains__ function to the rtevalCfgSection class  to make "in"
function correctly.

For example in cyclictest.py, self.__cfg is not a dictionary, it is an
instance of the rtevalCfgSection class, therefore
key in self.__cfg
does not work as expected. In order to make sure this is fixed
everywhere, instead of comparing to self.__cfg.keys() everywhere this is
used, implement the __contains__ function so that "in" works as
expected.

This bug was introduced by the commit fd3b732f714d ("rteval: 2to3
transformations")

Reported-by: Atsushi Nemoto <redacted>
Signed-off-by: John Kacur <jkacur@redhat.com>
Correction
Suggested-by: Jeff Epler <redacted>
Signed-off-by: John Kacur <jkacur@redhat.com>
---
 rteval/rtevalConfig.py | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/rteval/rtevalConfig.py b/rteval/rtevalConfig.py
index 578aaa3ab58f..56bbc9ee0de6 100644
--- a/rteval/rtevalConfig.py
+++ b/rteval/rtevalConfig.py
@@ -126,6 +126,8 @@ class rtevalCfgSection:
             return self.__cfgdata[key]
         return None
 
+    def __contains__(self, key):
+        return key in self.__cfgdata
 
     def items(self):
         return list(self.__cfgdata.items())
-- 
2.31.1
Thank you for review and correct fix.

---
Atsushi Nemoto
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help