Andreas Sandberg has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/15987

Change subject: python: Replace dict.has_key with 'key in dict'
......................................................................

python: Replace dict.has_key with 'key in dict'

Change-Id: I9852a5f57d672bea815308eb647a0ce45624fad5
Signed-off-by: Andreas Sandberg <[email protected]>
---
M src/python/m5/SimObject.py
M src/python/m5/params.py
M src/python/m5/util/multidict.py
3 files changed, 18 insertions(+), 18 deletions(-)



diff --git a/src/python/m5/SimObject.py b/src/python/m5/SimObject.py
index 1aa8dbe..722b665 100644
--- a/src/python/m5/SimObject.py
+++ b/src/python/m5/SimObject.py
@@ -537,7 +537,7 @@
                 cls._new_port(key, val)

             # init-time-only keywords
-            elif cls.init_keywords.has_key(key):
+            elif key in cls.init_keywords:
                 cls._set_keyword(key, val, cls.init_keywords[key])

             # default: use normal path (ends up in __setattr__)
@@ -616,11 +616,11 @@
             type.__setattr__(cls, attr, value)
             return

-        if cls.keywords.has_key(attr):
+        if attr in cls.keywords:
             cls._set_keyword(attr, value, cls.keywords[attr])
             return

-        if cls._ports.has_key(attr):
+        if attr in cls._ports:
             cls._cls_get_port_ref(attr).connect(value)
             return

@@ -655,10 +655,10 @@
         if attr == 'cxx_namespaces':
             return cls.cxx_class_path[:-1]

-        if cls._values.has_key(attr):
+        if attr in cls._values:
             return cls._values[attr]

-        if cls._children.has_key(attr):
+        if attr in cls._children:
             return cls._children[attr]

         raise AttributeError(
@@ -1161,7 +1161,7 @@
             # create a new dict and use that.
             memo_dict = {}
             kwargs['_memo'] = memo_dict
-        elif memo_dict.has_key(self):
+        elif self in memo_dict:
             # clone already done & memoized
             return memo_dict[self]
         return self.__class__(_ancestor = self, **kwargs)
@@ -1177,13 +1177,13 @@
         return ref

     def __getattr__(self, attr):
-        if self._ports.has_key(attr):
+        if attr in self._ports:
             return self._get_port_ref(attr)

-        if self._values.has_key(attr):
+        if attr in self._values:
             return self._values[attr]

-        if self._children.has_key(attr):
+        if attr in self._children:
             return self._children[attr]

         # If the attribute exists on the C++ object, transparently
@@ -1209,7 +1209,7 @@
             object.__setattr__(self, attr, value)
             return

-        if self._ports.has_key(attr):
+        if attr in self._ports:
             # set up port connection
             self._get_port_ref(attr).connect(value)
             return
@@ -1297,7 +1297,7 @@
         if child.has_parent():
             warn("add_child('%s'): child '%s' already has parent", name,
                 child.get_name())
-        if self._children.has_key(name):
+        if name in self._children:
# This code path had an undiscovered bug that would make it fail
             # at runtime. It had been here for a long time and was only
             # exposed by a buggy script. Changes here will probably not be
diff --git a/src/python/m5/params.py b/src/python/m5/params.py
index f76d7ae..742fb6b 100644
--- a/src/python/m5/params.py
+++ b/src/python/m5/params.py
@@ -161,12 +161,12 @@
             else:
                 raise TypeError('too many arguments')

-        if kwargs.has_key('desc'):
+        if 'desc' in kwargs:
             assert(not hasattr(self, 'desc'))
             self.desc = kwargs['desc']
             del kwargs['desc']

-        if kwargs.has_key('default'):
+        if 'default' in kwargs:
             assert(not hasattr(self, 'default'))
             self.default = kwargs['default']
             del kwargs['default']
@@ -1228,14 +1228,14 @@
         return cls

     def __init__(cls, name, bases, init_dict):
-        if init_dict.has_key('map'):
+        if 'map' in init_dict:
             if not isinstance(cls.map, dict):
                 raise TypeError("Enum-derived class attribute 'map' " \
                       "must be of type dict")
             # build list of value strings from map
             cls.vals = cls.map.keys()
             cls.vals.sort()
-        elif init_dict.has_key('vals'):
+        elif 'vals' in init_dict:
             if not isinstance(cls.vals, list):
                 raise TypeError("Enum-derived class attribute 'vals' " \
                       "must be of type list")
@@ -1859,7 +1859,7 @@
                   "cannot splice in new peers\n", self)

     def clone(self, simobj, memo):
-        if memo.has_key(self):
+        if self in memo:
             return memo[self]
         newRef = copy.copy(self)
         memo[self] = newRef
@@ -1982,7 +1982,7 @@
             self._get_next().connect(other)

     def clone(self, simobj, memo):
-        if memo.has_key(self):
+        if self in memo:
             return memo[self]
         newRef = copy.copy(self)
         memo[self] = newRef
diff --git a/src/python/m5/util/multidict.py b/src/python/m5/util/multidict.py
index 28090a2..58898a5 100644
--- a/src/python/m5/util/multidict.py
+++ b/src/python/m5/util/multidict.py
@@ -43,7 +43,7 @@
         return `dict(self.items())`

     def __contains__(self, key):
-        return self.local.has_key(key) or self.parent.has_key(key)
+        return key in self.local or key in self.parent

     def __delitem__(self, key):
         try:

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/15987
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I9852a5f57d672bea815308eb647a0ce45624fad5
Gerrit-Change-Number: 15987
Gerrit-PatchSet: 1
Gerrit-Owner: Andreas Sandberg <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to