Skip to content

Commit

Permalink
Drop Python 2: remove arguments from super calls
Browse files Browse the repository at this point in the history
This is no longer necesary in python 3. To remove all the occurrences
of this usage, the following command was used:

    find . -type f -not -path './.git*' -exec \
    sed -i 's/super([^)]*,[^)]*)/super()/g' {} +

The regex tries to find all instances of `super()` where there is
content between the parentheses. The search for `[^)]*` means to look
for all characters except a closing parens, which essentially makes the
search non-greedy. Having just that would not be enough and we have to
explicitly add another such clause separated by a comma. This is the
exact format required by python 2 where the `super` call expects two
arguments, first being the class itself and the second the reference,
typically `self` or `cls. By making the regex more specific we avoid
matching cases like:

    def test_without_super(self):

which would be replaced to

    def test_without_super():

if we don't include the explicit comma in the regex between the parens.
  • Loading branch information
sphuber committed Dec 2, 2019
1 parent 7531bd7 commit 0644e7d
Show file tree
Hide file tree
Showing 223 changed files with 483 additions and 483 deletions.
2 changes: 1 addition & 1 deletion .ci/polish/lib/template/workchain.tpl
Expand Up @@ -6,7 +6,7 @@ class ${class_name}(WorkChain):

@classmethod
def define(cls, spec):
super(${class_name}, cls).define(spec)
super().define(spec)
spec.input('code', valid_type=Code, required=False)
spec.input('operands', valid_type=Str)
spec.input('modulo', valid_type=Int)
Expand Down
6 changes: 3 additions & 3 deletions .ci/test_plugin_testcase.py
Expand Up @@ -34,7 +34,7 @@ def setUp(self):
self.computer = self.get_computer(temp_dir=self.temp_dir)

def tearDown(self):
super(PluginTestCase1, self).tearDown()
super().tearDown()
shutil.rmtree(self.temp_dir)

@staticmethod
Expand Down Expand Up @@ -88,7 +88,7 @@ def test_tear_down(self):
are not there anymore.
"""
from aiida.orm import load_node
super(PluginTestCase1, self).tearDown() # reset DB
super().tearDown() # reset DB
with self.assertRaises(Exception):
load_node(self.data_pk)

Expand All @@ -105,7 +105,7 @@ def test_dummy(self):
Just making sure that setup/teardown is safe for
multiple testcase classes (this was broken in #1425).
"""
super(PluginTestCase2, self).tearDown()
super().tearDown()


if __name__ == '__main__':
Expand Down
18 changes: 9 additions & 9 deletions .ci/workchains.py
Expand Up @@ -19,7 +19,7 @@ class NestedWorkChain(WorkChain):
"""
@classmethod
def define(cls, spec):
super(NestedWorkChain, cls).define(spec)
super().define(spec)
spec.input('inp', valid_type=Int)
spec.outline(
cls.do_submit,
Expand Down Expand Up @@ -53,7 +53,7 @@ def finalize(self):
class SerializeWorkChain(WorkChain):
@classmethod
def define(cls, spec):
super(SerializeWorkChain, cls).define(spec)
super().define(spec)

spec.input(
'test',
Expand All @@ -71,7 +71,7 @@ def echo(self):
class NestedInputNamespace(WorkChain):
@classmethod
def define(cls, spec):
super(NestedInputNamespace, cls).define(spec)
super().define(spec)

spec.input('foo.bar.baz', valid_type=Int)
spec.output('output', valid_type=Int)
Expand All @@ -84,7 +84,7 @@ def do_echo(self):
class ListEcho(WorkChain):
@classmethod
def define(cls, spec):
super(ListEcho, cls).define(spec)
super().define(spec)

spec.input('list', valid_type=List)
spec.output('output', valid_type=List)
Expand All @@ -98,7 +98,7 @@ def do_echo(self):
class DynamicNonDbInput(WorkChain):
@classmethod
def define(cls, spec):
super(DynamicNonDbInput, cls).define(spec)
super().define(spec)
spec.input_namespace('namespace', dynamic=True)
spec.output('output', valid_type=List)
spec.outline(cls.do_test)
Expand All @@ -113,7 +113,7 @@ def do_test(self):
class DynamicDbInput(WorkChain):
@classmethod
def define(cls, spec):
super(DynamicDbInput, cls).define(spec)
super().define(spec)
spec.input_namespace('namespace', dynamic=True)
spec.output('output', valid_type=Int)
spec.outline(cls.do_test)
Expand All @@ -127,7 +127,7 @@ def do_test(self):
class DynamicMixedInput(WorkChain):
@classmethod
def define(cls, spec):
super(DynamicMixedInput, cls).define(spec)
super().define(spec)
spec.input_namespace('namespace', dynamic=True)
spec.output('output', valid_type=Int)
spec.outline(cls.do_test)
Expand All @@ -147,7 +147,7 @@ class CalcFunctionRunnerWorkChain(WorkChain):
"""
@classmethod
def define(cls, spec):
super(CalcFunctionRunnerWorkChain, cls).define(spec)
super().define(spec)

spec.input('input', valid_type=Int)
spec.output('output', valid_type=Int)
Expand All @@ -164,7 +164,7 @@ class WorkFunctionRunnerWorkChain(WorkChain):
"""
@classmethod
def define(cls, spec):
super(WorkFunctionRunnerWorkChain, cls).define(spec)
super().define(spec)

spec.input('input', valid_type=Str)
spec.output('output', valid_type=Str)
Expand Down
6 changes: 3 additions & 3 deletions aiida/backends/djsite/db/models.py
Expand Up @@ -37,7 +37,7 @@
class AiidaQuerySet(QuerySet):
def iterator(self):
from aiida.orm.implementation.django import convert
for obj in super(AiidaQuerySet, self).iterator():
for obj in super().iterator():
yield convert.get_backend_entity(obj, None)

def __iter__(self):
Expand All @@ -46,15 +46,15 @@ def __iter__(self):
Note: used to rely on the iterator in django 1.8 but does no longer in django 1.11.
"""
from aiida.orm.implementation.django import convert
return (convert.get_backend_entity(model, None) for model in super(AiidaQuerySet, self).__iter__())
return (convert.get_backend_entity(model, None) for model in super().__iter__())

def __getitem__(self, key):
"""Get item for [] operator
Note: used to rely on the iterator in django 1.8 but does no longer in django 1.11.
"""
from aiida.orm.implementation.django import convert
res = super(AiidaQuerySet, self).__getitem__(key)
res = super().__getitem__(key)
return convert.get_backend_entity(res, None)


Expand Down
Expand Up @@ -244,7 +244,7 @@ def tearDown(self):
"""
db_setting_model = self.apps.get_model('db', 'DbSetting')
db_setting_model.objects.filter(key__in=self.settings_info.keys()).delete()
super(TestSettingsToJSONMigration, self).tearDown()
super().tearDown()


# pylint: disable=no-init, old-style-class, too-few-public-methods, dangerous-default-value, too-many-statements
Expand Down
Expand Up @@ -458,7 +458,7 @@ def tearDown(self):
DbNode.objects.all().delete() # pylint: disable=no-member
DbWorkflow.objects.all().delete() # pylint: disable=no-member
DbUser.objects.all().delete() # pylint: disable=no-member
super(TestDbLogMigrationRecordCleaning, self).tearDown()
super().tearDown()

def test_dblog_calculation_node(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/djsite/queries.py
Expand Up @@ -14,7 +14,7 @@
class DjangoQueryManager(AbstractQueryManager):

def __init__(self, backend):
super(DjangoQueryManager, self).__init__(backend)
super().__init__(backend)

def get_creation_statistics(
self,
Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/sqlalchemy/models/authinfo.py
Expand Up @@ -42,7 +42,7 @@ class DbAuthInfo(Base):
def __init__(self, *args, **kwargs):
self._metadata = dict()
self.auth_params = dict()
super(DbAuthInfo, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def __str__(self):
if self.enabled:
Expand Down
4 changes: 2 additions & 2 deletions aiida/backends/sqlalchemy/models/base.py
Expand Up @@ -47,12 +47,12 @@ class _AiidaQuery(orm.Query):

def __init__(self, *args, **kwargs):
"""Constructor"""
super(_AiidaQuery, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def __iter__(self):
from aiida.orm.implementation.sqlalchemy import convert

iterator = super(_AiidaQuery, self).__iter__()
iterator = super().__iter__()
for result in iterator:
# Allow the use of with_entities
if issubclass(type(result), Model):
Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/sqlalchemy/models/comment.py
Expand Up @@ -55,7 +55,7 @@ def __str__(self):
)

def __init__(self, *args, **kwargs):
super(DbComment, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
# The behavior of an unstored Comment instance should be that all its attributes should be initialized in
# accordance with the defaults specified on the collums, i.e. if a default is specified for the `uuid` column,
# then an unstored `DbComment` instance should have a default value for the `uuid` attribute. The exception here
Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/sqlalchemy/models/computer.py
Expand Up @@ -38,7 +38,7 @@ def __init__(self, *args, **kwargs):
if 'metadata' in kwargs.keys():
kwargs['_metadata'] = kwargs.pop('metadata')

super(DbComputer, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

@property
def pk(self):
Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/sqlalchemy/models/node.py
Expand Up @@ -79,7 +79,7 @@ class DbNode(Base):
)

def __init__(self, *args, **kwargs):
super(DbNode, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
# The behavior of an unstored Node instance should be that all its attributes should be initialized in
# accordance with the defaults specified on the colums, i.e. if a default is specified for the `uuid` column,
# then an unstored `DbNode` instance should have a default value for the `uuid` attribute. The exception here
Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/sqlalchemy/models/user.py
Expand Up @@ -29,7 +29,7 @@ def __init__(self, email, first_name='', last_name='', institution='', **kwargs)
self.first_name = first_name
self.last_name = last_name
self.institution = institution
super(DbUser, self).__init__(**kwargs)
super().__init__(**kwargs)

def __str__(self):
return self.email
2 changes: 1 addition & 1 deletion aiida/backends/sqlalchemy/queries.py
Expand Up @@ -17,7 +17,7 @@ class SqlaQueryManager(AbstractQueryManager):
"""

def __init__(self, backend):
super(SqlaQueryManager, self).__init__(backend)
super().__init__(backend)

def get_creation_statistics(
self,
Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/sqlalchemy/tests/test_generic.py
Expand Up @@ -60,7 +60,7 @@ class TestGroupsSqla(AiidaTestCase):

def setUp(self):
from aiida.orm.implementation import sqlalchemy as sqla
super(TestGroupsSqla, self).setUp()
super().setUp()
self.assertIsInstance(self.backend, sqla.backend.SqlaBackend)

def test_query(self):
Expand Down
8 changes: 4 additions & 4 deletions aiida/backends/sqlalchemy/tests/test_migrations.py
Expand Up @@ -46,15 +46,15 @@ def setUpClass(cls, *args, **kwargs):
"""
Prepare the test class with the alembivc configuration
"""
super(TestMigrationsSQLA, cls).setUpClass(*args, **kwargs)
super().setUpClass(*args, **kwargs)
cls.manager = manager.SqlaBackendManager()

def setUp(self):
"""
Go to the migrate_from revision, apply setUpBeforeMigration, then
run the migration.
"""
super(TestMigrationsSQLA, self).setUp()
super().setUp()
from aiida.orm import autogroup

self.current_autogroup = autogroup.current_autogroup
Expand Down Expand Up @@ -100,7 +100,7 @@ def tearDown(self):
from aiida.orm import autogroup
self._reset_database_and_schema()
autogroup.current_autogroup = self.current_autogroup
super(TestMigrationsSQLA, self).tearDown()
super().tearDown()

def setUpBeforeMigration(self): # pylint: disable=invalid-name
"""
Expand Down Expand Up @@ -649,7 +649,7 @@ def tearDown(self):
finally:
session.close()

super(TestDbLogMigrationRecordCleaning, self).tearDown()
super().tearDown()

def setUpBeforeMigration(self):
# pylint: disable=too-many-locals,too-many-statements
Expand Down
4 changes: 2 additions & 2 deletions aiida/backends/testbase.py
Expand Up @@ -205,12 +205,12 @@ def setUpClass(cls, *args, **kwargs):
"""Setup the PGTest postgres test cluster."""
from pgtest.pgtest import PGTest
cls.pg_test = PGTest()
super(AiidaPostgresTestCase, cls).setUpClass(*args, **kwargs)
super().setUpClass(*args, **kwargs)

@classmethod
def tearDownClass(cls, *args, **kwargs):
"""Close the PGTest postgres test cluster."""
super(AiidaPostgresTestCase, cls).tearDownClass(*args, **kwargs)
super().tearDownClass(*args, **kwargs)
cls.pg_test.close()


Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/tests/cmdline/commands/test_calcjob.py
Expand Up @@ -30,7 +30,7 @@ class TestVerdiCalculation(AiidaTestCase):

@classmethod
def setUpClass(cls, *args, **kwargs):
super(TestVerdiCalculation, cls).setUpClass(*args, **kwargs)
super().setUpClass(*args, **kwargs)
from aiida.common.links import LinkType
from aiida.engine import ProcessState

Expand Down
4 changes: 2 additions & 2 deletions aiida/backends/tests/cmdline/commands/test_code.py
Expand Up @@ -25,7 +25,7 @@ class TestVerdiCodeSetup(AiidaTestCase):

@classmethod
def setUpClass(cls, *args, **kwargs):
super(TestVerdiCodeSetup, cls).setUpClass(*args, **kwargs)
super().setUpClass(*args, **kwargs)
orm.Computer(
name='comp',
hostname='localhost',
Expand Down Expand Up @@ -134,7 +134,7 @@ class TestVerdiCodeCommands(AiidaTestCase):
def setUpClass(cls, *args, **kwargs):
from aiida import orm

super(TestVerdiCodeCommands, cls).setUpClass(*args, **kwargs)
super().setUpClass(*args, **kwargs)
orm.Computer(
name='comp',
hostname='localhost',
Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/tests/cmdline/commands/test_computer.py
Expand Up @@ -492,7 +492,7 @@ class TestVerdiComputerCommands(AiidaTestCase):
def setUpClass(cls, *args, **kwargs):
"""Create a new computer> I create a new one because I want to configure it and I don't want to
interfere with other tests"""
super(TestVerdiComputerCommands, cls).setUpClass(*args, **kwargs)
super().setUpClass(*args, **kwargs)
cls.computer_name = 'comp_cli_test_computer'
cls.comp = orm.Computer(
name=cls.computer_name,
Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/tests/cmdline/commands/test_daemon.py
Expand Up @@ -21,7 +21,7 @@ class TestVerdiDaemon(AiidaTestCase):
"""Tests for `verdi daemon` commands."""

def setUp(self):
super(TestVerdiDaemon, self).setUp()
super().setUp()
self.daemon_client = DaemonClient(get_config().current_profile)
self.cli_runner = CliRunner()

Expand Down

0 comments on commit 0644e7d

Please sign in to comment.