Commit 0b429771 authored by Leo Pound Singer's avatar Leo Pound Singer

Remove trivial super() args

In most cases, in Python 3, it is not necessary to pass any
arguments to `super()`. The following two class definitions are
equivalent:

```python
class Foo(Bar):
    def bat(self, baz):
        super(Foo, self).bat(baz)

class Foo(Bar):
    def bat(self, baz):
        super().bat(baz)
```

It is still necessary to pass explicit arguments to `super()` if
it is used outside of a class definition.
parent ff0b5b64
Pipeline #103893 passed with stages
in 56 minutes and 35 seconds
......@@ -402,7 +402,7 @@ class InterpolatedPSD(interpolate.interp1d):
keep = (f <= f_high_truncate * max(f))
f = f[keep]
S = S[keep]
super(InterpolatedPSD, self).__init__(
super().__init__(
np.log(f), np.log(S),
kind='linear', bounds_error=False, fill_value=np.log(fill_value))
self._f_min = min(f)
......@@ -427,7 +427,7 @@ class InterpolatedPSD(interpolate.interp1d):
'only sampled up to %g Hz', f_max, self._f_max)
return np.where(
(f >= self._f_min) & (f <= self._f_max),
np.exp(super(InterpolatedPSD, self).__call__(np.log(f))),
np.exp(super().__call__(np.log(f))),
np.exp(self.fill_value))
......
......@@ -54,4 +54,4 @@ class Sampler(ptemcee.sampler.Sampler):
if self._vectorize:
return self._likeprior(ps)
else:
return super(self).evaluate(ps)
return super().evaluate(ps)
......@@ -81,8 +81,7 @@ class LigoLWEventSource(OrderedDict, EventSource):
self._fallbackpath = (
os.path.dirname(filename) if filename else fallbackpath)
self._psds_for_file = lru_cache(maxsize=None)(self._psds_for_file)
super(LigoLWEventSource, self).__init__(
self._make_events(doc, psd_file, coinc_def))
super().__init__(self._make_events(doc, psd_file, coinc_def))
_template_keys = '''mass1 mass2
spin1x spin1y spin1z spin2x spin2y spin2z'''.split()
......
......@@ -39,8 +39,7 @@ class SQLiteEventSource(LigoLWEventSource):
else:
filename = f
db = sqlite.open(filename, 'r')
super(SQLiteEventSource, self).__init__(dbtables.get_xml(db),
*args, **kwargs)
super().__init__(dbtables.get_xml(db), *args, **kwargs)
self._fallbackpath = os.path.dirname(filename) if filename else None
......
......@@ -68,7 +68,7 @@ class BoundedKDE(gaussian_kde):
def __init__(self, pts, low=-np.inf, high=np.inf, periodic=False,
bw_method=None):
super(BoundedKDE, self).__init__(pts, bw_method=bw_method)
super().__init__(pts, bw_method=bw_method)
self._low = np.broadcast_to(
low, self.d).astype(self.dataset.dtype)
self._high = np.broadcast_to(
......@@ -86,7 +86,7 @@ class BoundedKDE(gaussian_kde):
pts_orig = pts
pts = np.copy(pts_orig)
den = super(BoundedKDE, self).evaluate(pts)
den = super().evaluate(pts)
for i, (low, high, period) in enumerate(zip(self._low, self._high,
self._periodic)):
......@@ -94,22 +94,22 @@ class BoundedKDE(gaussian_kde):
p = high - low
pts[i, :] += p
den += super(BoundedKDE, self).evaluate(pts)
den += super().evaluate(pts)
pts[i, :] -= 2.0 * p
den += super(BoundedKDE, self).evaluate(pts)
den += super().evaluate(pts)
pts[i, :] = pts_orig[i, :]
else:
if not np.isneginf(low):
pts[i, :] = 2.0 * low - pts[i, :]
den += super(BoundedKDE, self).evaluate(pts)
den += super().evaluate(pts)
pts[i, :] = pts_orig[i, :]
if not np.isposinf(high):
pts[i, :] = 2.0 * high - pts[i, :]
den += super(BoundedKDE, self).evaluate(pts)
den += super().evaluate(pts)
pts[i, :] = pts_orig[i, :]
return den
......@@ -321,11 +321,11 @@ class SkyKDE(ClusteredKDE):
def __init__(self, pts, max_k=40, trials=5, assign=None, jobs=1):
if assign is None:
pts = self.transform(pts)
super(SkyKDE, self).__init__(
super().__init__(
pts, max_k=max_k, trials=trials, assign=assign, jobs=jobs)
def __call__(self, pts):
return super(SkyKDE, self).__call__(self.transform(pts))
return super().__call__(self.transform(pts))
def _bayestar_adaptive_grid(self, top_nside=16, rounds=8):
"""Implement of the BAYESTAR adaptive mesh refinement scheme as
......@@ -441,7 +441,7 @@ class Clustered2DSkyKDE(SkyKDE, metaclass=_Clustered2DSkyKDEMeta):
frame = EigenFrame.for_coords(SkyCoord(*pts.T, unit='rad'))
name = '{:s}_{:x}'.format(cls.__name__, id(frame))
new_cls = type(name, (cls,), {'frame': frame})
return super(Clustered2DSkyKDE, cls).__new__(new_cls)
return super().__new__(new_cls)
def __reduce__(self):
"""Pickle instances of dynamically created subclasses of
......@@ -451,7 +451,7 @@ class Clustered2DSkyKDE(SkyKDE, metaclass=_Clustered2DSkyKDEMeta):
return _Clustered2DSkyKDE_factory, factory_args, self.__dict__
def eval_kdes(self, pts):
base = super(Clustered2DSkyKDE, self).eval_kdes
base = super().eval_kdes
dphis = (0.0, 2 * np.pi, -2 * np.pi)
phi, z = pts.T
return sum(base(np.column_stack((phi + dphi, z))) for dphi in dphis)
......@@ -487,13 +487,13 @@ class Clustered3DSkyKDE(SkyKDE):
"""Evaluate the posterior probability density in spherical polar
coordinates, as a function of (ra, dec, distance).
"""
return super(Clustered3DSkyKDE, self).__call__(pts)
return super().__call__(pts)
def as_healpix(self, top_nside=16):
"""Return a HEALPix multi-order map of the posterior density and
conditional distance distribution parameters.
"""
m = super(Clustered3DSkyKDE, self).as_healpix(top_nside=top_nside)
m = super().as_healpix(top_nside=top_nside)
order, ipix = moc.uniq2nest(m['UNIQ'])
nside = 2 ** order.astype(int)
theta, phi = hp.pix2ang(nside, ipix, nest=True)
......@@ -513,14 +513,14 @@ class Clustered2Plus1DSkyKDE(Clustered3DSkyKDE):
if assign is None:
self.twod = Clustered2DSkyKDE(
pts, max_k=max_k, trials=trials, assign=assign, jobs=jobs)
super(Clustered2Plus1DSkyKDE, self).__init__(
super().__init__(
pts, max_k=max_k, trials=trials, assign=assign, jobs=jobs)
def __call__(self, pts, distances=False):
probdensity = self.twod(pts)
if distances:
base = super(Clustered2Plus1DSkyKDE, self)
_, distmu, distsigma, distnorm = base.__call__(pts, distances=True)
_, distmu, distsigma, distnorm = super().__call__(
pts, distances=True)
return probdensity, distmu, distsigma, distnorm
else:
return probdensity
......@@ -529,5 +529,5 @@ class Clustered2Plus1DSkyKDE(Clustered3DSkyKDE):
"""Evaluate the posterior probability density in spherical polar
coordinates, as a function of (ra, dec, distance).
"""
base = super(Clustered2Plus1DSkyKDE, self)
return self(pts) * base.posterior_spherical(pts) / base.__call__(pts)
return self(pts) * super().posterior_spherical(pts) / super().__call__(
pts)
......@@ -125,7 +125,7 @@ class WCSInsetPatch(PathPatch):
def __init__(self, ax, *args, **kwargs):
self._ax = ax
super(WCSInsetPatch, self).__init__(
super().__init__(
None, *args, fill=False,
edgecolor=ax.coords.frame.get_color(),
linewidth=ax.coords.frame.get_linewidth(),
......@@ -152,7 +152,7 @@ class WCSInsetConnectionPatch(ConnectionPatch):
ax.coords.frame.transform.inverted())
xy_inset = corners[self._corners_map[loc]]
xy = transform.transform_point(xy_inset)
super(WCSInsetConnectionPatch, self).__init__(
super().__init__(
xy, xy_inset, 'data', 'data', ax, ax_inset, *args,
color=ax_inset.coords.frame.get_color(),
linewidth=ax_inset.coords.frame.get_linewidth(),
......@@ -167,7 +167,7 @@ class AutoScaledWCSAxes(WCSAxes):
name = 'astro wcs'
def __init__(self, *args, header, **kwargs):
super(AutoScaledWCSAxes, self).__init__(*args, aspect=1, **kwargs)
super().__init__(*args, aspect=1, **kwargs)
h = Header(header, copy=True)
naxis1 = h['NAXIS1']
naxis2 = h['NAXIS2']
......@@ -422,7 +422,7 @@ class GlobeAxes(AutoScaledWCSAxes):
'RADESYS': 'ICRS'}
if rotate is not None:
header['LONPOLE'] = u.Quantity(rotate).to_value(u.deg)
super(GlobeAxes, self).__init__(
super().__init__(
*args, frame_class=EllipticalFrame, header=header, **kwargs)
......@@ -449,7 +449,7 @@ class ZoomSkyAxes(AutoScaledWCSAxes):
'RADESYS': 'ICRS'}
if rotate is not None:
header['LONPOLE'] = u.Quantity(rotate).to_value(u.deg)
super(ZoomSkyAxes, self).__init__(*args, header=header, **kwargs)
super().__init__(*args, header=header, **kwargs)
class AllSkyAxes(AutoScaledWCSAxes):
......@@ -471,7 +471,7 @@ class AllSkyAxes(AutoScaledWCSAxes):
'RADESYS': self._radesys}
if obstime is not None:
header['DATE-OBS'] = Time(obstime).utc.isot
super(AllSkyAxes, self).__init__(
super().__init__(
*args, frame_class=EllipticalFrame, header=header, **kwargs)
self.coords[0].set_ticks(spacing=45 * u.deg)
self.coords[1].set_ticks(spacing=30 * u.deg)
......@@ -489,7 +489,7 @@ class Astro:
class GeoAngleFormatterLocator(AngleFormatterLocator):
def formatter(self, values, spacing):
return super(GeoAngleFormatterLocator, self).formatter(
return super().formatter(
reference_angle_deg(values.to(u.deg).value) * u.deg, spacing)
......@@ -500,7 +500,7 @@ class Geo(WCSAxes):
_ycoord = 'TLAT'
def __init__(self, *args, **kwargs):
super(Geo, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.invert_xaxis()
fl = self.coords[0]._formatter_locator
self.coords[0]._formatter_locator = GeoAngleFormatterLocator(
......@@ -514,7 +514,7 @@ class Degrees(WCSAxes):
"""WCS axes with longitude axis in degrees."""
def __init__(self, *args, **kwargs):
super(Degrees, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.coords[0].set_major_formatter('d')
......@@ -522,7 +522,7 @@ class Hours(WCSAxes):
"""WCS axes with longitude axis in hour angle."""
def __init__(self, *args, **kwargs):
super(Hours, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.coords[0].set_major_formatter('hh')
......@@ -603,7 +603,7 @@ class ScaleBar(FancyArrowPatch):
linewidth=rcParams['lines.linewidth'],
)
kwargs.update(custom_kwargs)
super(ScaleBar, self).__init__(
super().__init__(
xy, (x + dx, y),
*args,
arrowstyle='-',
......
......@@ -80,7 +80,7 @@ class PPPlot(axes.Axes):
def __init__(self, *args, **kwargs):
# Call parent constructor
super(PPPlot, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
# Square axes, limits from 0 to 1
self.set_aspect(1.0)
......
......@@ -75,7 +75,7 @@ class EnableAction(argparse.Action):
if not opt.startswith('--enable-'):
raise ValueError('Option string must start with --enable-')
option_strings = [opt, opt.replace('--enable-', '--disable-')]
super(EnableAction, self).__init__(
super().__init__(
option_strings,
dest=dest,
nargs=0,
......@@ -99,8 +99,7 @@ class GlobAction(argparse._StoreAction):
values = list(
itertools.chain.from_iterable(glob.iglob(s) for s in values))
if values:
super(GlobAction, self).__call__(
parser, namespace, values, *args, **kwargs)
super().__call__(parser, namespace, values, *args, **kwargs)
nvalues = getattr(namespace, self.dest)
nvalues = 0 if nvalues is None else len(nvalues)
if self.nargs == argparse.OPTIONAL:
......@@ -189,7 +188,7 @@ del group
class MatplotlibFigureType(FileType):
def __init__(self):
super(MatplotlibFigureType, self).__init__('wb')
super().__init__('wb')
@staticmethod
def __show():
......@@ -215,7 +214,7 @@ class MatplotlibFigureType(FileType):
plt.switch_backend(matplotlib.rcParamsOrig['backend'])
return self.__show
else:
with super(MatplotlibFigureType, self).__call__(string):
with super().__call__(string):
pass
plt.switch_backend('agg')
self.string = string
......@@ -230,7 +229,7 @@ class HelpChoicesAction(argparse.Action):
dest=argparse.SUPPRESS,
default=argparse.SUPPRESS):
name = option_strings[0].replace('--help-', '')
super(HelpChoicesAction, self).__init__(
super().__init__(
option_strings=option_strings,
dest=dest,
default=default,
......@@ -333,7 +332,7 @@ class LogLevelAction(argparse._StoreAction):
type=None, choices=None, required=False, help=None, metavar=None):
metavar = '|'.join(logging._levelToName.values())
type = loglevel_type
super(LogLevelAction, self).__init__(
super().__init__(
option_strings, dest, nargs=nargs, const=const, default=default,
type=type, choices=choices, required=required, help=help,
metavar=metavar)
......@@ -391,7 +390,7 @@ class ArgumentParser(argparse.ArgumentParser):
prog = prog.replace('_', '-').replace('.py', '')
if description is None:
description = parent_frame.f_globals.get('__doc__', None)
super(ArgumentParser, self).__init__(
super().__init__(
prog=prog,
usage=usage,
description=description,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment