kopia lustrzana https://github.com/micropython/micropython-lib
contextlib: Use a list instead of deque for exit callbacks.
Since deque was removed from this repository the built-in one needs to be used, and that doesn't have unbounded growth. So use a list instead, which is adequate becasue contextlib only needs append and pop, not double ended behaviour (the previous pure-Python implementation of deque that was used here anyway used a list as its storage container). Also tweak the excessive-nesting test so it uses less memory and can run on the unix port. Signed-off-by: Damien George <damien@micropython.org>pull/883/head
rodzic
0b0e0cc2df
commit
469b81b567
|
@ -85,13 +85,13 @@ class ExitStack(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._exit_callbacks = deque()
|
self._exit_callbacks = []
|
||||||
|
|
||||||
def pop_all(self):
|
def pop_all(self):
|
||||||
"""Preserve the context stack by transferring it to a new instance"""
|
"""Preserve the context stack by transferring it to a new instance"""
|
||||||
new_stack = type(self)()
|
new_stack = type(self)()
|
||||||
new_stack._exit_callbacks = self._exit_callbacks
|
new_stack._exit_callbacks = self._exit_callbacks
|
||||||
self._exit_callbacks = deque()
|
self._exit_callbacks = []
|
||||||
return new_stack
|
return new_stack
|
||||||
|
|
||||||
def _push_cm_exit(self, cm, cm_exit):
|
def _push_cm_exit(self, cm, cm_exit):
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
metadata(description="Port of contextlib for micropython", version="3.4.3")
|
metadata(description="Port of contextlib for micropython", version="3.4.4")
|
||||||
|
|
||||||
require("ucontextlib")
|
require("ucontextlib")
|
||||||
require("collections")
|
require("collections")
|
||||||
|
|
|
@ -399,7 +399,7 @@ class TestExitStack(unittest.TestCase):
|
||||||
def test_excessive_nesting(self):
|
def test_excessive_nesting(self):
|
||||||
# The original implementation would die with RecursionError here
|
# The original implementation would die with RecursionError here
|
||||||
with ExitStack() as stack:
|
with ExitStack() as stack:
|
||||||
for i in range(10000):
|
for i in range(5000):
|
||||||
stack.callback(int)
|
stack.callback(int)
|
||||||
|
|
||||||
def test_instance_bypass(self):
|
def test_instance_bypass(self):
|
||||||
|
|
Ładowanie…
Reference in New Issue