Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d910855

Browse files
committed
Remove apply()
1 parent fe55464 commit d910855

56 files changed

Lines changed: 179 additions & 285 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Demo/classes/bitvec.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def __repr__(self):
172172
def __cmp__(self, other, *rest):
173173
#rprt('%r.__cmp__%r\n' % (self, (other,) + rest))
174174
if type(other) != type(self):
175-
other = apply(bitvec, (other, ) + rest)
175+
other = bitvec(other, *rest)
176176
#expensive solution... recursive binary, with slicing
177177
length = self._len
178178
if length == 0 or other._len == 0:
@@ -237,7 +237,7 @@ def __setslice__(self, i, j, sequence, *rest):
237237
#rprt('%s.__setslice__%r\n' % (self, (i, j, sequence) + rest))
238238
i, j = _check_slice(self._len, i, j)
239239
if type(sequence) != type(self):
240-
sequence = apply(bitvec, (sequence, ) + rest)
240+
sequence = bitvec(sequence, *rest)
241241
#sequence is now of our own type
242242
ls_part = self[:i]
243243
ms_part = self[j:]
@@ -283,7 +283,7 @@ def __mul__(self, multiplier):
283283
def __and__(self, otherseq, *rest):
284284
#rprt('%r.__and__%r\n' % (self, (otherseq,) + rest))
285285
if type(otherseq) != type(self):
286-
otherseq = apply(bitvec, (otherseq, ) + rest)
286+
otherseq = bitvec(otherseq, *rest)
287287
#sequence is now of our own type
288288
return BitVec(self._data & otherseq._data, \
289289
min(self._len, otherseq._len))
@@ -292,7 +292,7 @@ def __and__(self, otherseq, *rest):
292292
def __xor__(self, otherseq, *rest):
293293
#rprt('%r.__xor__%r\n' % (self, (otherseq,) + rest))
294294
if type(otherseq) != type(self):
295-
otherseq = apply(bitvec, (otherseq, ) + rest)
295+
otherseq = bitvec(otherseq, *rest)
296296
#sequence is now of our own type
297297
return BitVec(self._data ^ otherseq._data, \
298298
max(self._len, otherseq._len))
@@ -301,7 +301,7 @@ def __xor__(self, otherseq, *rest):
301301
def __or__(self, otherseq, *rest):
302302
#rprt('%r.__or__%r\n' % (self, (otherseq,) + rest))
303303
if type(otherseq) != type(self):
304-
otherseq = apply(bitvec, (otherseq, ) + rest)
304+
otherseq = bitvec(otherseq, *rest)
305305
#sequence is now of our own type
306306
return BitVec(self._data | otherseq._data, \
307307
max(self._len, otherseq._len))
@@ -316,7 +316,7 @@ def __coerce__(self, otherseq, *rest):
316316
#needed for *some* of the arithmetic operations
317317
#rprt('%r.__coerce__%r\n' % (self, (otherseq,) + rest))
318318
if type(otherseq) != type(self):
319-
otherseq = apply(bitvec, (otherseq, ) + rest)
319+
otherseq = bitvec(otherseq, *rest)
320320
return self, otherseq
321321

322322
def __int__(self):

Demo/metaclasses/Eiffel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ def __init__(self, func, inst):
8282

8383
def __call__(self, *args, **kw):
8484
if self.pre:
85-
apply(self.pre, args, kw)
86-
Result = apply(self.func, (self.inst,) + args, kw)
85+
self.pre(*args, **kw)
86+
Result = self.func(self.inst, *args, **kw)
8787
if self.post:
88-
apply(self.post, (Result,) + args, kw)
88+
self.post(Result, *args, **kw)
8989
return Result
9090

9191
class EiffelHelper(MetaHelper):

Demo/metaclasses/Meta.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __init__(self, func, inst):
1414
self.__name__ = self.func.__name__
1515

1616
def __call__(self, *args, **kw):
17-
return apply(self.func, (self.inst,) + args, kw)
17+
return self.func(self.inst, *args, **kw)
1818

1919
class MetaHelper:
2020

@@ -86,7 +86,7 @@ def __call__(self, *args, **kw):
8686
init = inst.__getattr__('__init__')
8787
except AttributeError:
8888
init = lambda: None
89-
apply(init, args, kw)
89+
init(*args, **kw)
9090
return inst
9191

9292

Demo/metaclasses/Simple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(self, function, instance):
2828
self.instance = instance
2929
def __call__(self, *args):
3030
print "calling", self.function, "for", self.instance, "with", args
31-
return apply(self.function, (self.instance,) + args)
31+
return self.function(self.instance, *args)
3232

3333
Trace = Tracing('Trace', (), {})
3434

Demo/metaclasses/Synch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ def f1(lock, f2=f2, done=done):
148148
class LockingMethodWrapper(MetaMethodWrapper):
149149
def __call__(self, *args, **kw):
150150
if self.__name__[:1] == '_' and self.__name__[1:] != '_':
151-
return apply(self.func, (self.inst,) + args, kw)
151+
return self.func(self.inst, *args, **kw)
152152
self.inst.__lock__.acquire()
153153
try:
154-
return apply(self.func, (self.inst,) + args, kw)
154+
return self.func(self.inst, *args, **kw)
155155
finally:
156156
self.inst.__lock__.release()
157157

Demo/metaclasses/Trace.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __call__(self, *args, **kw):
5050
init = inst.__getattr__('__init__')
5151
except AttributeError:
5252
init = lambda: None
53-
apply(init, args, kw)
53+
init(*args, **kw)
5454
return inst
5555

5656
__trace_output__ = None
@@ -85,15 +85,15 @@ def __init__(self, name, func, inst):
8585
self.func = func
8686
self.inst = inst
8787
def __call__(self, *args, **kw):
88-
return apply(self.func, (self.inst,) + args, kw)
88+
return self.func(self.inst, *args, **kw)
8989

9090
class TracingWrapper(NotTracingWrapper):
9191
def __call__(self, *args, **kw):
9292
self.inst.__trace_call__(self.inst.__trace_output__,
9393
"calling %s, inst=%s, args=%s, kw=%s",
9494
self.__name__, self.inst, args, kw)
9595
try:
96-
rv = apply(self.func, (self.inst,) + args, kw)
96+
rv = self.func(self.inst, *args, **kw)
9797
except:
9898
t, v, tb = sys.exc_info()
9999
self.inst.__trace_call__(self.inst.__trace_output__,

Demo/pdist/RCSProxy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def test():
186186
if hasattr(proxy, what):
187187
attr = getattr(proxy, what)
188188
if callable(attr):
189-
print apply(attr, tuple(sys.argv[2:]))
189+
print attr(*sys.argv[2:])
190190
else:
191191
print repr(attr)
192192
else:

Demo/pdist/client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,11 @@ def _flush(self):
132132
class SecureClient(Client, Security):
133133

134134
def __init__(self, *args):
135-
import string
136-
apply(self._pre_init, args)
135+
self._pre_init(*args)
137136
Security.__init__(self)
138137
self._wf.flush()
139138
line = self._rf.readline()
140-
challenge = string.atoi(string.strip(line))
139+
challenge = int(line.strip())
141140
response = self._encode_challenge(challenge)
142141
line = repr(long(response))
143142
if line[-1] in 'Ll': line = line[:-1]

Demo/pdist/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def _dorequest(self, rf, wf):
8181
raise NameError, "illegal method name %s" % repr(methodname)
8282
else:
8383
method = getattr(self, methodname)
84-
reply = (None, apply(method, args), id)
84+
reply = (None, method(*args), id)
8585
except:
8686
reply = (sys.exc_info()[:2], id)
8787
if id < 0 and reply[:2] == (None, None):
@@ -117,7 +117,7 @@ def _listmethods(self, cl=None):
117117
class SecureServer(Server, Security):
118118

119119
def __init__(self, *args):
120-
apply(Server.__init__, (self,) + args)
120+
Server.__init__(self, *args)
121121
Security.__init__(self)
122122

123123
def _verify(self, conn, address):

Demo/threads/Coroutine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def _start(self, me, *args):
115115
if not self.killed:
116116
try:
117117
try:
118-
apply(me.f, args)
118+
me.f(*args)
119119
except Killed:
120120
pass
121121
finally:

0 commit comments

Comments
 (0)