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

Skip to content

Commit eeec25c

Browse files
authored
Merge pull request #16326 from timhoffm/stack
Cleanup stack
2 parents f2b3051 + 965ea02 commit eeec25c

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ def __init__(self, default=None):
624624

625625
def __call__(self):
626626
"""Return the current element, or None."""
627-
if not len(self._elements):
627+
if not self._elements:
628628
return self._default
629629
else:
630630
return self._elements[self._pos]
@@ -662,7 +662,7 @@ def home(self):
662662
663663
The first element is returned.
664664
"""
665-
if not len(self._elements):
665+
if not self._elements:
666666
return
667667
self.push(self._elements[0])
668668
return self()
@@ -678,33 +678,43 @@ def clear(self):
678678

679679
def bubble(self, o):
680680
"""
681-
Raise *o* to the top of the stack. *o* must be present in the stack.
681+
Raise all references of *o* to the top of the stack, and return it.
682682
683-
*o* is returned.
683+
Raises
684+
------
685+
ValueError
686+
If *o* is not in the stack.
684687
"""
685688
if o not in self._elements:
686-
raise ValueError('Unknown element o')
687-
old = self._elements[:]
689+
raise ValueError('Given element not contained in the stack')
690+
old_elements = self._elements.copy()
688691
self.clear()
689-
bubbles = []
690-
for thiso in old:
691-
if thiso == o:
692-
bubbles.append(thiso)
692+
top_elements = []
693+
for elem in old_elements:
694+
if elem == o:
695+
top_elements.append(elem)
693696
else:
694-
self.push(thiso)
695-
for _ in bubbles:
697+
self.push(elem)
698+
for _ in top_elements:
696699
self.push(o)
697700
return o
698701

699702
def remove(self, o):
700-
"""Remove *o* from the stack."""
703+
"""
704+
Remove *o* from the stack.
705+
706+
Raises
707+
------
708+
ValueError
709+
If *o* is not in the stack.
710+
"""
701711
if o not in self._elements:
702-
raise ValueError('Unknown element o')
703-
old = self._elements[:]
712+
raise ValueError('Given element not contained in the stack')
713+
old_elements = self._elements.copy()
704714
self.clear()
705-
for thiso in old:
706-
if thiso != o:
707-
self.push(thiso)
715+
for elem in old_elements:
716+
if elem != o:
717+
self.push(elem)
708718

709719

710720
def report_memory(i=0): # argument may go away

0 commit comments

Comments
 (0)