Skip to content

Commit 597a35a

Browse files
committed
Fix python 2.7 compatibility for calling super()
1 parent c54e98d commit 597a35a

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

command_runner/__init__.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ def __init__(self, cmd, timeout, output=None, stderr=None, *args, **kwargs):
122122
self.timeout = timeout
123123
self.output = output
124124
self.stderr = stderr
125-
super().__init__(*args, **kwargs)
125+
try:
126+
super().__init__(*args, **kwargs)
127+
except TypeError:
128+
# python 2.7 needs super(Baseclass, self)
129+
super(BaseException, self).__init__(*args, **kwargs)
126130

127131
def __str__(self):
128132
return "Command '%s' timed out after %s seconds" % (self.cmd, self.timeout)
@@ -145,7 +149,11 @@ class InterruptGetOutput(BaseException):
145149

146150
def __init__(self, output, *args, **kwargs):
147151
self._output = output
148-
super().__init__(*args, **kwargs)
152+
try:
153+
super().__init__(*args, **kwargs)
154+
except TypeError:
155+
# python 2.7 needs super(Baseclass, self)
156+
super(BaseException, self).__init__(*args, **kwargs)
149157

150158
@property
151159
def output(self):
@@ -159,7 +167,11 @@ class KbdInterruptGetOutput(InterruptGetOutput):
159167

160168
def __init__(self, output, *args, **kwargs):
161169
self._output = output
162-
super().__init__(output, *args, **kwargs)
170+
try:
171+
super().__init__(*args, **kwargs)
172+
except TypeError:
173+
# python 2.7 needs super(Baseclass, self)
174+
super(InterruptGetOutput, self).__init__(*args, **kwargs)
163175

164176
@property
165177
def output(self):
@@ -173,7 +185,11 @@ class StopOnInterrupt(InterruptGetOutput):
173185

174186
def __init__(self, output, *args, **kwargs):
175187
self._output = output
176-
super().__init__(output, *args, **kwargs)
188+
try:
189+
super().__init__(*args, **kwargs)
190+
except TypeError:
191+
# python 2.7 needs super(Baseclass, self)
192+
super(InterruptGetOutput, self).__init__(*args, **kwargs)
177193

178194
@property
179195
def output(self):

0 commit comments

Comments
 (0)