Skip to content

Commit de1e43d

Browse files
Merge pull request #187 from DiamondLightSource/remove___super_attribute
Remove unnecessary __super and __init__class__
2 parents ba24655 + 9b24380 commit de1e43d

File tree

3 files changed

+12
-50
lines changed

3 files changed

+12
-50
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Changed:
2727
- `AsyncioDispatcher cleanup tasks atexit <../../pull/138>`_
2828
- `Ensure returned numpy arrays are not writeable <../../pull/164>`_
2929
- `Ensure records do not get stuck in processing state <../../pull/175>`_
30+
- `Remove __super attribute <../../pull/187>`_
3031

3132
Fixed:
3233

softioc/device.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class ProcessDeviceSupportCore(DeviceSupportCore, RecordLookup):
5757
def __init__(self, name, **kargs):
5858
autosave_fields = kargs.pop("autosave", None)
5959
autosave.add_pv_to_autosave(self, name, autosave_fields)
60-
self.__super.__init__(name, **kargs)
60+
super().__init__(name, **kargs)
6161

6262
# Most subclasses (all except waveforms) define a ctypes constructor for the
6363
# underlying EPICS compatible value.
@@ -127,7 +127,7 @@ def __init__(self, name, **kargs):
127127
# The tuple contains everything needed to be written: the value,
128128
# severity, alarm and optional timestamp.
129129
self._value = (value, alarm.NO_ALARM, alarm.UDF_ALARM, None)
130-
self.__super.__init__(name, **kargs)
130+
super().__init__(name, **kargs)
131131

132132
def _process(self, record):
133133
# For input process we copy the value stored in the instance to the
@@ -197,7 +197,7 @@ def __init__(self, name, **kargs):
197197
if self._blocking:
198198
self._callback = create_callback_capsule()
199199

200-
self.__super.__init__(name, **kargs)
200+
super().__init__(name, **kargs)
201201

202202
def init_record(self, record):
203203
'''Special record initialisation for out records only: implements
@@ -385,7 +385,7 @@ def _process(self, record):
385385
# Because we're returning NO_CONVERT we need to do the .UDF updating
386386
# ourself (otherwise the record support layer does this).
387387
record.UDF = int(numpy.isnan(self._value[0]))
388-
return self.__super._process(record)
388+
return super()._process(record)
389389

390390
class ao(ProcessDeviceSupportOut):
391391
_record_type_ = 'ao'
@@ -439,11 +439,11 @@ class WaveformBase(ProcessDeviceSupportCore):
439439
def __init__(self, name, _wf_nelm, _wf_dtype, **kargs):
440440
self._dtype = _wf_dtype
441441
self._nelm = _wf_nelm
442-
self.__super.__init__(name, **kargs)
442+
super().__init__(name, **kargs)
443443

444444
def init_record(self, record):
445445
self._dbf_type_ = record.FTVL
446-
return self.__super.init_record(record)
446+
return super().init_record(record)
447447

448448
def _read_value(self, record):
449449
nord = record.NORD

softioc/device_core.py

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,11 @@
11
from __future__ import print_function
22

3-
import sys
43
from . import imports
54
from .fields import RecordFactory
65
from ctypes import *
76

87

9-
# Black magic lifted from six.py (http://pypi.python.org/pypi/six/) to replace
10-
# use of __metaclass__ for metaclass definition
11-
def with_metaclass(meta, *bases):
12-
class metaclass(meta):
13-
def __new__(cls, name, this_bases, d):
14-
return meta(name, bases, d)
15-
return type.__new__(metaclass, 'temporary_class', (), {})
16-
17-
18-
class InitClass(type):
19-
def __new__(cls, name, bases, dict):
20-
if '__init_class__' in dict:
21-
dict['__init_class__'] = classmethod(dict['__init_class__'])
22-
return type.__new__(cls, name, bases, dict)
23-
24-
def __init__(cls, name, bases, dict):
25-
type.__init__(cls, name, bases, dict)
26-
# Binds self.__super.method to the appropriate superclass method
27-
setattr(cls, '_%s__super' % name.lstrip('_'), super(cls))
28-
# Binds cls.__super_cls().method to the appropriate superclass
29-
# class method. Unfortunately the .__super form doesn't work
30-
# with class methods, only instance methods.
31-
setattr(
32-
cls, '_%s__super_cls' % name,
33-
classmethod(lambda child: super(cls, child)))
34-
# Finally call the class initialisatio nmethod.
35-
cls.__init_class__()
36-
37-
class DeviceCommon(with_metaclass(InitClass)):
38-
'''Adds support for an __init_class__ method called when the class or any
39-
of its subclasses is constructed. Also adds auto-super functionality
40-
(see iocbuilder.support.autosuper).'''
41-
42-
def __init_class__(cls): pass
43-
8+
class DeviceCommon:
449
# By requiring that DeviceCommon be a common base class for the entire
4510
# Python device hierarchy, we can use this __init__ to test for unused
4611
# keyword arguments.
@@ -83,20 +48,16 @@ class DeviceSupportCore(DeviceCommon):
8348
# treatment) are then bound to the appropriate class instance and the
8449
# appropriate method is invoked.
8550

86-
def __init_class__(cls):
51+
def __init_subclass__(cls):
8752
'''Record support initialisation, called once during class
8853
initialisation for each sub-class. This registers record support for
8954
the specified device name.'''
55+
9056
if not hasattr(cls, '_record_type_'):
9157
# If no record type has been specified then we're a base class
9258
# with nothing to do.
9359
return
9460

95-
# Create an empty device directory.
96-
# (Potentially this belongs in a mix-in for resolving the linkage
97-
# between record and instances, but for now this is hard-wired here.)
98-
cls.__device_directory = {}
99-
10061
# Convert the list of fields into a dictionary suitable for record
10162
# lookup.
10263
fields = set([cls._link_] + cls.__preset_fields + cls._fields_)
@@ -194,7 +155,7 @@ def __init__(self, name, **kargs):
194155
# a call to get_ioinit_info. This is only a trivial attempt to
195156
# reduce resource consumption.
196157
self.__ioscanpvt = imports.IOSCANPVT()
197-
self.__super.__init__(name, **kargs)
158+
super().__init__(name, **kargs)
198159

199160

200161
def init_record(self, record):
@@ -245,7 +206,7 @@ def __init__(self, name, **kargs):
245206
'Record %s already registered' % name
246207
self._name = name
247208
self._RecordDirectory[name] = self
248-
self.__super.__init__(name, **kargs)
209+
super().__init__(name, **kargs)
249210

250211

251212
LookupRecord = RecordLookup.LookupRecord

0 commit comments

Comments
 (0)