From 3296fd8d8948208253640b0a9d74b0bfe70f2c7d Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Wed, 31 Aug 2022 11:46:12 +0200 Subject: [PATCH] User super() instead of referencing parent classes explicitly --- osc/OscConfigParser.py | 6 +++--- osc/checker.py | 2 +- osc/core.py | 6 +++--- osc/oscerr.py | 34 +++++++++++++++++----------------- osc/util/ar.py | 4 ++-- osc/util/cpio.py | 2 +- osc/util/packagequery.py | 2 +- tests/common.py | 2 +- tests/test_init_package.py | 2 +- tests/test_init_project.py | 2 +- tests/test_request.py | 2 +- tests/test_results.py | 2 +- tests/test_setlinkrev.py | 2 +- 13 files changed, 34 insertions(+), 34 deletions(-) diff --git a/osc/OscConfigParser.py b/osc/OscConfigParser.py index a78ab4b5..1f917d63 100644 --- a/osc/OscConfigParser.py +++ b/osc/OscConfigParser.py @@ -93,7 +93,7 @@ class SectionLine(Line): CommentLine() or OptionLine() instances. """ def __init__(self, sectname): - Line.__init__(self, sectname, 'section') + super().__init__(sectname, 'section') self._lines = [] def _find(self, name): @@ -155,7 +155,7 @@ class SectionLine(Line): class CommentLine(Line): """Store a commentline""" def __init__(self, line): - Line.__init__(self, line.strip('\n'), 'comment') + super().__init__(line.strip('\n'), 'comment') def __str__(self): return self.name @@ -176,7 +176,7 @@ class OptionLine(Line): """ def __init__(self, optname, line): - Line.__init__(self, optname, 'option') + super().__init__(optname, 'option') self.name = optname self.format(line) diff --git a/osc/checker.py b/osc/checker.py index 645bb691..ee7712be 100644 --- a/osc/checker.py +++ b/osc/checker.py @@ -8,7 +8,7 @@ import rpm class KeyError(Exception): def __init__(self, key, *args): - Exception.__init__(self) + super().__init__() self.args = args self.key = key def __str__(self): diff --git a/osc/core.py b/osc/core.py index 3aff425f..527b9106 100644 --- a/osc/core.py +++ b/osc/core.py @@ -2569,7 +2569,7 @@ class ReviewState(AbstractState): if not review_node.get('state'): raise oscerr.APIError('invalid review node (state attr expected): %s' % \ ET.tostring(review_node, encoding=ET_ENCODING)) - AbstractState.__init__(self, review_node.tag) + super().__init__(review_node.tag) self.state = review_node.get('state') self.by_user = review_node.get('by_user') self.by_group = review_node.get('by_group') @@ -2597,7 +2597,7 @@ class RequestHistory(AbstractState): re_name = re.compile(r'^Request (?:got )?([^\s]+)$') def __init__(self, history_node): - AbstractState.__init__(self, history_node.tag) + super().__init__(history_node.tag) self.who = history_node.get('who') self.when = history_node.get('when') if not history_node.find('description') is None and \ @@ -2639,7 +2639,7 @@ class RequestState(AbstractState): if not state_node.get('name'): raise oscerr.APIError('invalid request state node (name attr expected): %s' % \ ET.tostring(state_node, encoding=ET_ENCODING)) - AbstractState.__init__(self, state_node.tag) + super().__init__(state_node.tag) self.name = state_node.get('name') self.who = state_node.get('who') self.when = state_node.get('when') diff --git a/osc/oscerr.py b/osc/oscerr.py index 81a9bb19..b67b9f3f 100644 --- a/osc/oscerr.py +++ b/osc/oscerr.py @@ -7,7 +7,7 @@ class OscBaseError(Exception): def __init__(self, args=()): - Exception.__init__(self) + super().__init__() self.args = args def __str__(self): return ''.join(self.args) @@ -18,7 +18,7 @@ class UserAbort(OscBaseError): class ConfigError(OscBaseError): """Exception raised when there is an error in the config file""" def __init__(self, msg, fname): - OscBaseError.__init__(self) + super().__init__() self.msg = msg self.file = fname @@ -28,24 +28,24 @@ class ConfigError(OscBaseError): class ConfigMissingApiurl(ConfigError): """Exception raised when a apiurl does not exist in the config file""" def __init__(self, msg, fname, url): - ConfigError.__init__(self, msg, fname) + super().__init__(msg, fname) self.url = url class ConfigMissingCredentialsError(ConfigError): def __init__(self, msg, fname, url): - ConfigError.__init__(self, msg, fname) + super().__init__(msg, fname) self.url = url class APIError(OscBaseError): """Exception raised when there is an error in the output from the API""" def __init__(self, msg): - OscBaseError.__init__(self) + super().__init__() self.msg = msg class NoConfigfile(OscBaseError): """Exception raised when osc's configfile cannot be found""" def __init__(self, fname, msg): - OscBaseError.__init__(self) + super().__init__() self.file = fname self.msg = msg @@ -55,14 +55,14 @@ class NoConfigfile(OscBaseError): class ExtRuntimeError(OscBaseError): """Exception raised when there is a runtime error of an external tool""" def __init__(self, msg, fname): - OscBaseError.__init__(self) + super().__init__() self.msg = msg self.file = fname class ServiceRuntimeError(OscBaseError): """Exception raised when the execution of a source service failed""" def __init__(self, msg): - OscBaseError.__init__(self) + super().__init__() self.msg = msg class WrongArgs(OscBaseError): @@ -98,26 +98,26 @@ class WorkingCopyOutdated(OscBaseError): class PackageError(OscBaseError): """Base class for all Package related exceptions""" def __init__(self, prj, pac): - OscBaseError.__init__(self) + super().__init__() self.prj = prj self.pac = pac class WorkingCopyInconsistent(PackageError): """Exception raised when the working copy is in an inconsistent state""" def __init__(self, prj, pac, dirty_files, msg): - PackageError.__init__(self, prj, pac) + super().__init__(prj, pac) self.dirty_files = dirty_files self.msg = msg class LinkExpandError(PackageError): """Exception raised when source link expansion fails""" def __init__(self, prj, pac, msg): - PackageError.__init__(self, prj, pac) + super().__init__(prj, pac) self.msg = msg class OscIOError(OscBaseError): def __init__(self, e, msg): - OscBaseError.__init__(self) + super().__init__() self.e = e self.msg = msg @@ -142,7 +142,7 @@ class PackageNotInstalled(OscBaseError): Exception raised when a package is not installed on local system """ def __init__(self, pkg): - OscBaseError.__init__(self, (pkg,)) + super().__init__((pkg,)) def __str__(self): return 'Package %s is required for this operation' % self.args @@ -155,7 +155,7 @@ class PackageExists(PackageError): Exception raised when a local object already exists """ def __init__(self, prj, pac, msg): - PackageError.__init__(self, prj, pac) + super().__init__(prj, pac) self.msg = msg class PackageMissing(PackageError): @@ -163,7 +163,7 @@ class PackageMissing(PackageError): Exception raised when a local object doesn't exist """ def __init__(self, prj, pac, msg): - PackageError.__init__(self, prj, pac) + super().__init__(prj, pac) self.msg = msg class PackageFileConflict(PackageError): @@ -172,12 +172,12 @@ class PackageFileConflict(PackageError): Conflict doesn't mean an unsuccessfull merge in this context. """ def __init__(self, prj, pac, file, msg): - PackageError.__init__(self, prj, pac) + super().__init__(prj, pac) self.file = file self.msg = msg class PackageInternalError(PackageError): def __init__(self, prj, pac, msg): - PackageError.__init__(self, prj, pac) + super().__init__(prj, pac) self.msg = msg # vim: sw=4 et diff --git a/osc/util/ar.py b/osc/util/ar.py index 8eb106fd..db800d7b 100644 --- a/osc/util/ar.py +++ b/osc/util/ar.py @@ -28,7 +28,7 @@ if not hasattr(os, 'SEEK_SET'): class ArError(Exception): """Base class for all ar related errors""" def __init__(self, fn, msg): - Exception.__init__(self) + super().__init__() self.file = fn self.msg = msg @@ -57,7 +57,7 @@ class ArHdr: class ArFile(BytesIO): """Represents a file which resides in the archive""" def __init__(self, fn, uid, gid, mode, buf): - BytesIO.__init__(self, buf) + super().__init__(buf) self.name = fn self.uid = uid self.gid = gid diff --git a/osc/util/cpio.py b/osc/util/cpio.py index 7d41b564..1f706e99 100644 --- a/osc/util/cpio.py +++ b/osc/util/cpio.py @@ -30,7 +30,7 @@ if not hasattr(os, 'SEEK_SET'): class CpioError(Exception): """base class for all cpio related errors""" def __init__(self, fn, msg): - Exception.__init__(self) + super().__init__() self.file = fn self.msg = msg def __str__(self): diff --git a/osc/util/packagequery.py b/osc/util/packagequery.py index a70a5568..3b76e763 100644 --- a/osc/util/packagequery.py +++ b/osc/util/packagequery.py @@ -4,7 +4,7 @@ from .helper import decode_it class PackageError(Exception): """base class for all package related errors""" def __init__(self, fname, msg): - Exception.__init__(self) + super().__init__() self.fname = fname self.msg = msg diff --git a/tests/common.py b/tests/common.py index db0f4ee2..d3b17823 100644 --- a/tests/common.py +++ b/tests/common.py @@ -65,7 +65,7 @@ def xml_equal(actual, exp): class RequestWrongOrder(Exception): """raised if an unexpected request is issued to urllib2""" def __init__(self, url, exp_url, method, exp_method): - Exception.__init__(self) + super().__init__() self.url = url self.exp_url = exp_url self.method = method diff --git a/tests/test_init_package.py b/tests/test_init_package.py index 30519ac4..61201aec 100644 --- a/tests/test_init_package.py +++ b/tests/test_init_package.py @@ -22,7 +22,7 @@ class TestInitPackage(OscTestCase): def tearDown(self): if os.path.exists(os.path.join(FIXTURES_DIR, 'osctest')): os.rmdir(os.path.join(FIXTURES_DIR, 'osctest')) - OscTestCase.tearDown(self) + super().tearDown() def test_simple(self): """initialize a package dir""" diff --git a/tests/test_init_project.py b/tests/test_init_project.py index ca3d69f5..7fa4526d 100644 --- a/tests/test_init_project.py +++ b/tests/test_init_project.py @@ -22,7 +22,7 @@ class TestInitProject(OscTestCase): def tearDown(self): if os.path.exists(os.path.join(FIXTURES_DIR, 'osctest')): os.rmdir(os.path.join(FIXTURES_DIR, 'osctest')) - OscTestCase.tearDown(self) + super().tearDown() def test_simple(self): """initialize a project dir""" diff --git a/tests/test_request.py b/tests/test_request.py index 9bd84b7a..4dde5a74 100644 --- a/tests/test_request.py +++ b/tests/test_request.py @@ -18,7 +18,7 @@ class TestRequest(OscTestCase): return FIXTURES_DIR def setUp(self): - OscTestCase.setUp(self, copytree=False) + super().setUp(copytree=False) def test_createsr(self): """create a simple submitrequest""" diff --git a/tests/test_results.py b/tests/test_results.py index 384eae2b..ed8317bc 100644 --- a/tests/test_results.py +++ b/tests/test_results.py @@ -12,7 +12,7 @@ def suite(): class TestResults(OscTestCase): def setUp(self): - OscTestCase.setUp(self, copytree=False) + super().setUp(copytree=False) def _get_fixtures_name(self): return 'results_fixtures' diff --git a/tests/test_setlinkrev.py b/tests/test_setlinkrev.py index 8b01b810..8e50e777 100644 --- a/tests/test_setlinkrev.py +++ b/tests/test_setlinkrev.py @@ -14,7 +14,7 @@ def suite(): class TestSetLinkRev(OscTestCase): def setUp(self): - OscTestCase.setUp(self, copytree=False) + super().setUp(copytree=False) def _get_fixtures_dir(self): return FIXTURES_DIR