Skip to content

Commit 469b81b

Browse files
committed
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>
1 parent 0b0e0cc commit 469b81b

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

python-stdlib/contextlib/contextlib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ class ExitStack(object):
8585
"""
8686

8787
def __init__(self):
88-
self._exit_callbacks = deque()
88+
self._exit_callbacks = []
8989

9090
def pop_all(self):
9191
"""Preserve the context stack by transferring it to a new instance"""
9292
new_stack = type(self)()
9393
new_stack._exit_callbacks = self._exit_callbacks
94-
self._exit_callbacks = deque()
94+
self._exit_callbacks = []
9595
return new_stack
9696

9797
def _push_cm_exit(self, cm, cm_exit):

python-stdlib/contextlib/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
metadata(description="Port of contextlib for micropython", version="3.4.3")
1+
metadata(description="Port of contextlib for micropython", version="3.4.4")
22

33
require("ucontextlib")
44
require("collections")

python-stdlib/contextlib/tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ def test_exit_exception_chaining_suppress(self):
399399
def test_excessive_nesting(self):
400400
# The original implementation would die with RecursionError here
401401
with ExitStack() as stack:
402-
for i in range(10000):
402+
for i in range(5000):
403403
stack.callback(int)
404404

405405
def test_instance_bypass(self):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy