misc: Use python 3's argumentless super().

When calling a method in a superclass, you can/should use the super()
method to get a reference to that class. The python 2 version of that
method takes two parameters, the current class name, and the "self"
instance. The python 3 version takes no arguments. This is better for a
at least three reasons.

First, this version is less verbose because you don't have to specify
any arguments.

Second, you don't have to remember which argument goes where (I always
have to look it up), and you can't accidentally use the wrong class
name, or forget to update it if you copy code from a different class.

Third, this version will work correctly if you use a class decorator.
I don't know exactly how the mechanics of this work, but it is referred
to in a comment on this stackoverflow question:

https://stackoverflow.com/questions/681953/how-to-decorate-a-class

Change-Id: I427737c8f767e80da86cd245642e3b057121bc3b
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/52224
Reviewed-by: Gabe Black <gabe.black@gmail.com>
Maintainer: Gabe Black <gabe.black@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Gabe Black
2021-10-28 16:16:07 -07:00
parent e4cff7b5ca
commit ba5f68db3d
142 changed files with 301 additions and 370 deletions

View File

@@ -63,7 +63,7 @@ class BaseProxy(object):
if not attr.startswith('_'):
raise AttributeError(
"cannot set attribute '%s' on proxy object" % attr)
super(BaseProxy, self).__setattr__(attr, value)
super().__setattr__(attr, value)
def _gen_op(operation):
def op(self, operand):
@@ -163,14 +163,14 @@ class BaseProxy(object):
class AttrProxy(BaseProxy):
def __init__(self, search_self, search_up, attr):
super(AttrProxy, self).__init__(search_self, search_up)
super().__init__(search_self, search_up)
self._attr = attr
self._modifiers = []
def __getattr__(self, attr):
# python uses __bases__ internally for inheritance
if attr.startswith('_'):
return super(AttrProxy, self).__getattr__(self, attr)
return super().__getattr__(self, attr)
if hasattr(self, '_pdesc'):
raise AttributeError("Attribute reference on bound proxy "
f"({self}.{attr})")