QUERY · ISSUE
collections.deque constructor does not take keyword arguments
enhancementpy-core
I would like to construct a deque as follows collections.deque(maxlen=10). For this to work, iterables must have a default. The default should be an empty tuple or None, see: https://docs.python.org/3/library/collections.html#collections.deque
maxlen should also support keyword arguments but would not require a default, i.e not optional, since I don't need arbitrarily (unbounded) length deques.
CANDIDATE · PULL REQUEST
Add support of `len` to `collections.deque`
Currently collections.deque in micropython doesn't support len:
>>> from collections.deque import deque
>>> q = deque()
>>> len(q)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: object of type 'deque' has no len()
But cpython supports:
In [1]: from collections import deque
In [2]: q = deque()
In [3]: len(q)
Out[3]: 0
So I've added it to micropython collections.deque.
I've also added
__bool__for supporting:Thanks, merged! Minor nitpick: can you please follow existing commit message format "module: Description": (I rebase-reworded your messages):
https://github.com/micropython/micropython-lib/commits/master . I also "optimized"
__bool__: https://github.com/micropython/micropython-lib/commit/df85a27af439ad66f99eb2b9a91359559d65a2e4 ;-). Pushed to PyPI as 0.1.1.Thanks, sure.