Skip to content

Commit

Permalink
Call super() without args, do not explicitly subclass object
Browse files Browse the repository at this point in the history
  • Loading branch information
dhadka committed Sep 10, 2024
1 parent 64a1ac3 commit 177e8a8
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 111 deletions.
2 changes: 1 addition & 1 deletion examples/Basic/dps_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class CubicDPSLever(Lever):

def __init__(self, name, length = 1, c_bounds = (-2, 2), r_bounds = (0, 2)):
super(CubicDPSLever, self).__init__(name)
super().__init__(name)
self.length = length
self.c_bounds = c_bounds
self.r_bounds = r_bounds
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dynamic = ["version"] # Version is read from rhodium/__init__.py
[project.optional-dependencies]
test = ["pytest", "mock", "rhodium[examples]"]
openmdao = ["openmdao"]
windows = ["win32com"]
examples = ["pandas[excel]", "pyper<=1.1.2"]

[tool.setuptools.dynamic]
Expand Down
7 changes: 2 additions & 5 deletions rhodium/brush.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .config import RhodiumConfig
from .model import DataSet

class Brush(object):
class Brush:
"""Defines a brush to color data points matching an expression.
A brush is a mechanism to highlight, or color, data that matches a given
Expand All @@ -35,16 +35,14 @@ class Brush(object):
"""

def __init__(self, name, expr=None, color=None):
super(Brush, self).__init__()

if expr is None:
expr = name

self.name = name
self.expr = expr
self.color = color

class BrushSet(object):
class BrushSet:
"""A collection of Brush objects.
If two or more brushes overlap, then the first brush, in the order they
Expand All @@ -54,7 +52,6 @@ class BrushSet(object):
"""

def __init__(self, brushes):
super(BrushSet, self).__init__()
self.map = OrderedDict()

if not isinstance(brushes, (list, tuple)):
Expand Down
4 changes: 1 addition & 3 deletions rhodium/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from prim import Prim
from io import BytesIO, StringIO

class Cart(object):
class Cart:

def __init__(self,
x,
Expand Down Expand Up @@ -62,8 +62,6 @@ def __init__(self,
exclude : list of str
the names of variables excluded from the PRIM analysis
"""
super(Cart, self).__init__()

# Ensure the input x is a numpy matrix/array
if isinstance(x, pd.DataFrame):
x = x.to_records(index=False)
Expand Down
3 changes: 1 addition & 2 deletions rhodium/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
import seaborn as sns
from platypus.config import PlatypusConfig

class _RhodiumConfig(object):
class _RhodiumConfig:

def __init__(self):
super(_RhodiumConfig, self).__init__()
self.default_cmap = plt.get_cmap("rainbow")
self.default_brush_colors = sns.color_palette()
self.default_unassigned_brush_color = mpl.colors.colorConverter.to_rgb("#CCCCCC")
Expand Down
56 changes: 20 additions & 36 deletions rhodium/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@
INFO = Response.INFO
IGNORE = Response.IGNORE

class UnnamedObject(object):
class UnnamedObject:

def __init__(self, constructor, *args, **kwargs):
super(UnnamedObject, self).__init__()
self.constructor = constructor
self.args = args
self.kwargs = kwargs
Expand All @@ -41,48 +40,48 @@ def convert(self, name):
class Real(UnnamedObject):

def __init__(self, *args, **kwargs):
super(Real, self).__init__(RealLever, *args, **kwargs)
super().__init__(RealLever, *args, **kwargs)

class Integer(UnnamedObject):

def __init__(self, *args, **kwargs):
super(Integer, self).__init__(IntegerLever, *args, **kwargs)
super().__init__(IntegerLever, *args, **kwargs)

class Categorical(UnnamedObject):

def __init__(self, *args, **kwargs):
super(Categorical, self).__init__(CategoricalLever, *args, **kwargs)
super().__init__(CategoricalLever, *args, **kwargs)

class Permutation(UnnamedObject):

def __init__(self, *args, **kwargs):
super(Permutation, self).__init__(PermutationLever, *args, **kwargs)
super().__init__(PermutationLever, *args, **kwargs)

class Subset(UnnamedObject):

def __init__(self, *args, **kwargs):
super(Subset, self).__init__(SubsetLever, *args, **kwargs)
super().__init__(SubsetLever, *args, **kwargs)

class Uniform(float, UnnamedObject):

def __init__(self, *args, **kwargs):
super(Uniform, self).__init__(UniformUncertainty, *args, **kwargs)
super().__init__(UniformUncertainty, *args, **kwargs)

def __new__(cls, *args, **kwargs):
return float.__new__(cls, kwargs.get("default_value", float("NaN")))

class Normal(float, UnnamedObject):

def __init__(self, *args, **kwargs):
super(Normal, self).__init__(NormalUncertainty, *args, **kwargs)
super().__init__(NormalUncertainty, *args, **kwargs)

def __new__(cls, *args, **kwargs):
return float.__new__(cls, kwargs.get("default_value", float("NaN")))

class LogNormal(float, UnnamedObject):

def __init__(self, *args, **kwargs):
super(LogNormal, self).__init__(LogNormalUncertainty, *args, **kwargs)
super().__init__(LogNormalUncertainty, *args, **kwargs)

def __new__(cls, *args, **kwargs):
return float.__new__(cls, kwargs.get("default_value", float("NaN")))
Expand All @@ -91,32 +90,32 @@ def __new__(cls, *args, **kwargs):
class Minimize(Response):

def __init__(self, name, **kwargs):
super(Minimize, self).__init__(name, type=Response.MINIMIZE, **kwargs)
super().__init__(name, type=Response.MINIMIZE, **kwargs)

class Maximize(Response):

def __init__(self, name, **kwargs):
super(Maximize, self).__init__(name, type=Response.MAXIMIZE, **kwargs)
super().__init__(name, type=Response.MAXIMIZE, **kwargs)

class Info(Response):

def __init__(self, name, **kwargs):
super(Info, self).__init__(name, type=Response.INFO, **kwargs)
super().__init__(name, type=Response.INFO, **kwargs)

class Ignore(Response):

def __init__(self, **kwargs):
super(Ignore, self).__init__("Ignored" + str(random.randint()), type=Response.IGNORE, **kwargs)
super().__init__("Ignored" + str(random.randint()), type=Response.IGNORE, **kwargs)

class CallableModel(Model):

def __init__(self, function):
super(CallableModel, self).__init__(function)
super().__init__(function)

def __call__(self, *args, **kwargs):
return self.function(*args, **kwargs)

class RhodiumModel(object):
class RhodiumModel:

def __init__(self, *args, **kwargs):
self.args = args
Expand Down Expand Up @@ -148,7 +147,7 @@ def __call__(self, f):

return f.rhodium_model

class Parameters(object):
class Parameters:

def __init__(self, *args, **kwargs):
self.args = args
Expand Down Expand Up @@ -176,7 +175,7 @@ def __call__(self, f):

return f

class Responses(object):
class Responses:

def __init__(self, *args, **kwargs):
self.args = args
Expand All @@ -186,21 +185,6 @@ def __call__(self, f):
if not hasattr(f, "rhodium_model"):
f.rhodium_model = CallableModel(f)

# if len(self.args) == 2 and isinstance(self.args[0], (list, tuple)) and isinstance(self.args[1], (list, tuple)):
# for i, v in enumerate(self.args[0]):
# f.rhodium_model.responses[v] = Response(v, self.args[1][i if i < len(self.args[1]) else -1])
# elif len(self.args) == 1 and isinstance(self.args[0], (list, tuple)):
# for v in self.args[0]:
# f.rhodiuim_model.responses[v] = Response(v, Response.INFO)
# else:
# for v in self.args:
# if isinstance(v, str):
# f.rhodium_model.responses[v] = Response(v, Response.INFO)
# elif isinstance(v, Response):
# f.rhodium_model.responses[v.name] = v
# else:
# raise ValueError("arg must be a string or Response")

for v in self.args:
if isinstance(v, str):
f.rhodium_model.responses[v] = Response(v, Response.INFO)
Expand All @@ -221,7 +205,7 @@ def __call__(self, f):

return f

class Constraints(object):
class Constraints:

def __init__(self, *args):
self.args = args
Expand All @@ -240,7 +224,7 @@ def __call__(self, f):

return f

class Levers(object):
class Levers:

def __init__(self, *args, **kwargs):
self.args = args
Expand All @@ -264,7 +248,7 @@ def __call__(self, f):

return f

class Uncertainties(object):
class Uncertainties:

def __init__(self, *args, **kwargs):
self.args = args
Expand Down
7 changes: 3 additions & 4 deletions rhodium/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
from win32com.universal import com_error
from .model import Model

class ExcelHelper(object):
class ExcelHelper:

def __init__(self, filename, sheet=1, visible=False):
super(ExcelHelper, self).__init__()
self.xl = win32com.client.Dispatch("Excel.Application")
self.wb = self.xl.Workbooks.Open(filename)

Expand Down Expand Up @@ -91,7 +90,7 @@ def __setitem__(self, cell, value):
class ExcelModel(Model):

def __init__(self, filename, **kwargs):
super(ExcelModel, self).__init__(self._evaluate)
super().__init__(self._evaluate)
self.excel_helper = ExcelHelper(filename, **kwargs)

def _evaluate(self, **kwargs):
Expand Down Expand Up @@ -126,4 +125,4 @@ def _evaluate(self, **kwargs):

def close(self):
self.excel_helper.close()
super(ExcelModel, self).close()
super().close()
2 changes: 1 addition & 1 deletion rhodium/ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class NativeModel(Model):

def __init__(self, library, function, mode=ctypes.CDLL):
super(NativeModel, self).__init__(self._evaluate)
super().__init__(self._evaluate)
self._cdll = mode(library)
self._func = getattr(self._cdll, function)

Expand Down
Loading

0 comments on commit 177e8a8

Please sign in to comment.