Skip to content

Commit

Permalink
Use no-argument form of super()
Browse files Browse the repository at this point in the history
Now that we require Python 3, we can use
the simpler and less error-prone no-argument
form of super() to access the Python base class.
  • Loading branch information
benmwebb committed Jun 5, 2024
1 parent 0ab637f commit 41b1236
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion modules/core/test/test_direction.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DirectionRestraint(IMP.Restraint):
"""Harmonically restrain a Direction to a vector."""

def __init__(self, m, pi, v, k):
super(DirectionRestraint, self).__init__(m, "DirectionRestraint%1%")
super().__init__(m, "DirectionRestraint%1%")
self.pi, self.u = pi, v.get_unit_vector()
self.uf = IMP.core.Cosine(k, 1, 0)

Expand Down
2 changes: 1 addition & 1 deletion modules/core/test/test_direction_angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AngleRestraint(IMP.Restraint):
"""Harmonically restrain an angle between two directions to a value."""

def __init__(self, m, pi, a, k):
super(AngleRestraint, self).__init__(m, "AngleRestraint%1%")
super().__init__(m, "AngleRestraint%1%")
self.pi = pi
self.a = a
self.k = k
Expand Down
2 changes: 1 addition & 1 deletion modules/core/test/test_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class TestVisitor(IMP.core.HierarchyVisitor):
def __init__(self, descend=True):
super(TestVisitor, self).__init__()
super().__init__()
self.descend = descend
self.seen = []
def __call__(self, h):
Expand Down
4 changes: 2 additions & 2 deletions modules/kernel/pyext/IMP_kernel.argparse.i
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class ArgumentParser(argparse.ArgumentParser):
def __init__(self, *args, **kwargs):
# Don't add --help option (since the Boost option parser handles it)
kwargs['add_help'] = False
super(ArgumentParser, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
for ntoken in (0, 1):
flags = _get_all_flags(ntoken)
for f in flags:
Expand All @@ -85,7 +85,7 @@ class ArgumentParser(argparse.ArgumentParser):
@returns args
"""
self._boost_command_line = [sys.argv[0]]
ret = super(ArgumentParser, self).parse_args(args, namespace)
ret = super().parse_args(args, namespace)
if len(self._boost_command_line) > 1:
self._handle_boost()
return ret
Expand Down
44 changes: 22 additions & 22 deletions modules/mmcif/pyext/src/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class _EntityMapper(dict):
share sequence."""
def __init__(self, system):
self.system = system
super(_EntityMapper, self).__init__()
super().__init__()
self._sequence_dict = {}
self._entities = []
self._alphabet_map = {
Expand Down Expand Up @@ -165,7 +165,7 @@ def __init__(self, entity, asym_id, name):
class _ComponentMapper:
"""Handle mapping from IMP Chains to CIF AsymUnits."""
def __init__(self, system):
super(_ComponentMapper, self).__init__()
super().__init__()
self.system = system
self._used_entities = set()
self._all_components = []
Expand Down Expand Up @@ -385,12 +385,12 @@ class _StartingModel(ihm.startmodel.StartingModel):

def __init__(self, asym_unit, struc_prov):
self.filename = struc_prov[0].get_filename()
super(_StartingModel, self).__init__(
asym_unit=asym_unit(0, 0), # will update in _add_residue()
# will fill in later with _set_sources_datasets()
dataset=None,
asym_id=struc_prov[0].get_chain_id(),
offset=struc_prov[0].get_residue_offset())
super().__init__(
asym_unit=asym_unit(0, 0), # will update in _add_residue()
# will fill in later with _set_sources_datasets()
dataset=None,
asym_id=struc_prov[0].get_chain_id(),
offset=struc_prov[0].get_residue_offset())

def _add_residue(self, resind):
# Update seq_id_range to accommodate this residue
Expand Down Expand Up @@ -519,7 +519,7 @@ def _get_starting_model(sp, resind):
class _Datasets:
"""Store all datasets used."""
def __init__(self, system):
super(_Datasets, self).__init__()
super().__init__()
self._datasets = {}
self._groups = {}
self.system = system
Expand Down Expand Up @@ -563,7 +563,7 @@ class _AllSoftware:
def __init__(self, system):
self.system = system
self._by_namever = {}
super(_AllSoftware, self).__init__()
super().__init__()

def add_hierarchy(self, h, top_h=None):
# todo: if no SoftwareProvenance available, use RMF producer field
Expand Down Expand Up @@ -627,18 +627,18 @@ def __init__(self, prov, num_models_begin, assembly, all_software):
method = prov.get_method()
if prov.get_number_of_replicas() > 1:
method = "Replica exchange " + method
super(_ProtocolStep, self).__init__(
assembly=assembly,
# todo: fill in useful value for dataset_group
dataset_group=None,
method=method, name='Sampling',
num_models_begin=num_models_begin,
num_models_end=prov.get_number_of_frames(),
# todo: support multiple states, time ordered
multi_state=False, ordered=False,
# todo: revisit assumption all models are multiscale
multi_scale=True,
software=all_software._add_previous_provenance(prov))
super().__init__(
assembly=assembly,
# todo: fill in useful value for dataset_group
dataset_group=None,
method=method, name='Sampling',
num_models_begin=num_models_begin,
num_models_end=prov.get_number_of_frames(),
# todo: support multiple states, time ordered
multi_state=False, ordered=False,
# todo: revisit assumption all models are multiscale
multi_scale=True,
software=all_software._add_previous_provenance(prov))

def add_combine(self, prov):
self.num_models_end = prov.get_number_of_frames()
Expand Down
10 changes: 5 additions & 5 deletions modules/mmcif/pyext/src/restraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __init__(self, imp_restraint, info, components, system):
self._asyms = tuple(asyms)
p = IMP.mmcif.metadata._GMMParser()
r = p.parse_file(info['filename'])
super(_EM3DRestraint, self).__init__(
super().__init__(
dataset=r['dataset'], assembly=assembly,
number_of_gaussians=r['number_of_gaussians'],
fitting_method='Gaussian mixture model')
Expand Down Expand Up @@ -157,7 +157,7 @@ def __init__(self, imp_restraint, info, components, image_number):
details="Electron microscopy class average")
dataset = ihm.dataset.EM2DClassDataset(loc)

super(_EM2DRestraint, self).__init__(
super().__init__(
dataset=dataset, assembly=assembly,
segment=False,
number_raw_micrographs=info['micrographs number'] or None,
Expand Down Expand Up @@ -203,7 +203,7 @@ def __init__(self, imp_restraint, info, components, system):
loc = ihm.location.InputFileLocation(
info['filename'], details='SAXS profile')
dataset = ihm.dataset.SASDataset(loc)
super(_SAXSRestraint, self).__init__(
super().__init__(
dataset=dataset, assembly=assembly,
segment=False, fitting_method='IMP SAXS restraint',
fitting_atom_type=info['form factor type'],
Expand Down Expand Up @@ -232,7 +232,7 @@ def __init__(self, imp_restraint, info, components, system):
smiles_canonical=info.get('linker smiles canonical'),
inchi=info.get('linker inchi'),
inchi_key=info.get('linker inchi key'))
super(_CrossLinkRestraint, self).__init__(
super().__init__(
dataset=dataset, linker=linker)
# Map from IMP/RMF chain names to ihm.Entity
cmap = {e.description: e for e in system.entities}
Expand Down Expand Up @@ -292,7 +292,7 @@ class _GeometricRestraint(ihm.restraint.GeometricRestraint):
def __init__(self, imp_restraint, info, components, system):
self._info = info
asym = _AsymMapper(imp_restraint.get_model(), components)
super(_GeometricRestraint, self).__init__(
super().__init__(
dataset=None,
geometric_object=self._geom_object,
feature=asym.get_feature(
Expand Down
18 changes: 9 additions & 9 deletions modules/test/pyext/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ def __del__(self):
class _TestResult(unittest.TextTestResult):

def __init__(self, stream=None, descriptions=None, verbosity=None):
super(_TestResult, self).__init__(stream, descriptions, verbosity)
super().__init__(stream, descriptions, verbosity)
self.all_tests = []

def stopTestRun(self):
Expand All @@ -851,10 +851,10 @@ def stopTestRun(self):
fname = Path("Z:") / fname
with open(str(fname), 'wb') as fh:
pickle.dump(self.all_tests, fh, protocol)
super(_TestResult, self).stopTestRun()
super().stopTestRun()

def startTest(self, test):
super(_TestResult, self).startTest(test)
super().startTest(test)
test.start_time = datetime.datetime.now()

def _test_finished(self, test, state, detail=None):
Expand Down Expand Up @@ -884,27 +884,27 @@ def _test_finished(self, test, state, detail=None):

def addSuccess(self, test):
self._test_finished(test, 'OK')
super(_TestResult, self).addSuccess(test)
super().addSuccess(test)

def addError(self, test, err):
self._test_finished(test, 'ERROR', err)
super(_TestResult, self).addError(test, err)
super().addError(test, err)

def addFailure(self, test, err):
self._test_finished(test, 'FAIL', err)
super(_TestResult, self).addFailure(test, err)
super().addFailure(test, err)

def addSkip(self, test, reason):
self._test_finished(test, 'SKIP', reason)
super(_TestResult, self).addSkip(test, reason)
super().addSkip(test, reason)

def addExpectedFailure(self, test, err):
self._test_finished(test, 'EXPFAIL', err)
super(_TestResult, self).addExpectedFailure(test, err)
super().addExpectedFailure(test, err)

def addUnexpectedSuccess(self, test):
self._test_finished(test, 'UNEXPSUC')
super(_TestResult, self).addUnexpectedSuccess(test)
super().addUnexpectedSuccess(test)

def getDescription(self, test):
doc_first_line = test.shortDescription()
Expand Down

0 comments on commit 41b1236

Please sign in to comment.