Code modernization. Replace v=s[i]; del s[i] with single lookup v=s.pop(i)
This commit is contained in:
parent
78e057a32a
commit
46ac8eb3c8
|
@ -146,6 +146,4 @@ class Queue:
|
|||
|
||||
# Get an item from the queue
|
||||
def _get(self):
|
||||
item = self.queue[0]
|
||||
del self.queue[0]
|
||||
return item
|
||||
return self.queue.pop(0)
|
||||
|
|
|
@ -269,9 +269,7 @@ class fifo:
|
|||
|
||||
def pop (self):
|
||||
if self.list:
|
||||
result = self.list[0]
|
||||
del self.list[0]
|
||||
return (1, result)
|
||||
return (1, self.list.pop(0))
|
||||
else:
|
||||
return (0, None)
|
||||
|
||||
|
|
|
@ -323,8 +323,7 @@ def parse_header(line):
|
|||
|
||||
"""
|
||||
plist = map(lambda x: x.strip(), line.split(';'))
|
||||
key = plist[0].lower()
|
||||
del plist[0]
|
||||
key = plist.pop(0).lower()
|
||||
pdict = {}
|
||||
for p in plist:
|
||||
i = p.find('=')
|
||||
|
|
|
@ -109,8 +109,7 @@ class Cmd:
|
|||
stop = None
|
||||
while not stop:
|
||||
if self.cmdqueue:
|
||||
line = self.cmdqueue[0]
|
||||
del self.cmdqueue[0]
|
||||
line = self.cmdqueue.pop(0)
|
||||
else:
|
||||
if self.use_rawinput:
|
||||
try:
|
||||
|
@ -261,11 +260,10 @@ class Cmd:
|
|||
names = []
|
||||
classes = [self.__class__]
|
||||
while classes:
|
||||
aclass = classes[0]
|
||||
aclass = classes.pop(0)
|
||||
if aclass.__bases__:
|
||||
classes = classes + list(aclass.__bases__)
|
||||
names = names + dir(aclass)
|
||||
del classes[0]
|
||||
return names
|
||||
|
||||
def complete_help(self, *args):
|
||||
|
|
|
@ -973,11 +973,10 @@ class IMAP4:
|
|||
return typ, dat
|
||||
if not name in self.untagged_responses:
|
||||
return typ, [None]
|
||||
data = self.untagged_responses[name]
|
||||
data = self.untagged_responses.pop(name)
|
||||
if __debug__:
|
||||
if self.debug >= 5:
|
||||
self._mesg('untagged_responses[%s] => %s' % (name, data))
|
||||
del self.untagged_responses[name]
|
||||
return typ, data
|
||||
|
||||
|
||||
|
|
|
@ -202,8 +202,7 @@ class MHMailbox:
|
|||
def next(self):
|
||||
if not self.boxes:
|
||||
return None
|
||||
fn = self.boxes[0]
|
||||
del self.boxes[0]
|
||||
fn = self.boxes.pop(0)
|
||||
fp = open(os.path.join(self.dirname, fn))
|
||||
return self.factory(fp)
|
||||
|
||||
|
@ -233,8 +232,7 @@ class Maildir:
|
|||
def next(self):
|
||||
if not self.boxes:
|
||||
return None
|
||||
fn = self.boxes[0]
|
||||
del self.boxes[0]
|
||||
fn = self.boxes.pop(0)
|
||||
fp = open(fn)
|
||||
return self.factory(fp)
|
||||
|
||||
|
|
|
@ -160,8 +160,7 @@ class MultiFile:
|
|||
self.level = max(0, self.level - 1)
|
||||
del self.stack[0]
|
||||
if self.seekable:
|
||||
self.start = self.posstack[0]
|
||||
del self.posstack[0]
|
||||
self.start = self.posstack.pop(0)
|
||||
if self.level > 0:
|
||||
self.lastpos = abslastpos - self.start
|
||||
|
||||
|
|
|
@ -44,8 +44,7 @@ class mutex:
|
|||
"""Unlock a mutex. If the queue is not empty, call the next
|
||||
function with its argument."""
|
||||
if self.queue:
|
||||
function, argument = self.queue[0]
|
||||
del self.queue[0]
|
||||
function, argument = self.queue.pop(0)
|
||||
function(argument)
|
||||
else:
|
||||
self.locked = 0
|
||||
|
|
|
@ -692,11 +692,7 @@ class Unpickler:
|
|||
dispatch[PERSID] = load_persid
|
||||
|
||||
def load_binpersid(self):
|
||||
stack = self.stack
|
||||
|
||||
pid = stack[-1]
|
||||
del stack[-1]
|
||||
|
||||
pid = self.stack.pop()
|
||||
self.append(self.persistent_load(pid))
|
||||
dispatch[BINPERSID] = load_binpersid
|
||||
|
||||
|
@ -977,8 +973,7 @@ class Unpickler:
|
|||
|
||||
def load_append(self):
|
||||
stack = self.stack
|
||||
value = stack[-1]
|
||||
del stack[-1]
|
||||
value = stack.pop()
|
||||
list = stack[-1]
|
||||
list.append(value)
|
||||
dispatch[APPEND] = load_append
|
||||
|
@ -995,9 +990,8 @@ class Unpickler:
|
|||
|
||||
def load_setitem(self):
|
||||
stack = self.stack
|
||||
value = stack[-1]
|
||||
key = stack[-2]
|
||||
del stack[-2:]
|
||||
value = stack.pop()
|
||||
key = stack.pop()
|
||||
dict = stack[-1]
|
||||
dict[key] = value
|
||||
dispatch[SETITEM] = load_setitem
|
||||
|
@ -1014,8 +1008,7 @@ class Unpickler:
|
|||
|
||||
def load_build(self):
|
||||
stack = self.stack
|
||||
value = stack[-1]
|
||||
del stack[-1]
|
||||
value = stack.pop()
|
||||
inst = stack[-1]
|
||||
try:
|
||||
setstate = inst.__setstate__
|
||||
|
@ -1038,8 +1031,7 @@ class Unpickler:
|
|||
dispatch[MARK] = load_mark
|
||||
|
||||
def load_stop(self):
|
||||
value = self.stack[-1]
|
||||
del self.stack[-1]
|
||||
value = self.stack.pop()
|
||||
raise _Stop(value)
|
||||
dispatch[STOP] = load_stop
|
||||
|
||||
|
|
|
@ -633,8 +633,7 @@ def _test():
|
|||
while not self.queue:
|
||||
self._note("get(): queue empty")
|
||||
self.rc.wait()
|
||||
item = self.queue[0]
|
||||
del self.queue[0]
|
||||
item = self.queue.pop(0)
|
||||
self._note("get(): got %s, %d left", item, len(self.queue))
|
||||
self.wc.notify()
|
||||
self.mon.release()
|
||||
|
|
|
@ -779,16 +779,14 @@ class Unmarshaller:
|
|||
dispatch["name"] = end_string # struct keys are always strings
|
||||
|
||||
def end_array(self, data):
|
||||
mark = self._marks[-1]
|
||||
del self._marks[-1]
|
||||
mark = self._marks.pop()
|
||||
# map arrays to Python lists
|
||||
self._stack[mark:] = [self._stack[mark:]]
|
||||
self._value = 0
|
||||
dispatch["array"] = end_array
|
||||
|
||||
def end_struct(self, data):
|
||||
mark = self._marks[-1]
|
||||
del self._marks[-1]
|
||||
mark = self._marks.pop()
|
||||
# map structs to Python dictionaries
|
||||
dict = {}
|
||||
items = self._stack[mark:]
|
||||
|
|
Loading…
Reference in New Issue