← index #5244Issue #13495
Related · high · value 2.121
QUERY · ISSUE

collections.deque constructor does not take keyword arguments

openby nevercastopened 2019-10-21updated 2019-11-15
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 · ISSUE

deque bug ?

closedby pidou46opened 2024-01-22updated 2024-01-23
py-core

from doc:

class collections.deque(iterable, maxlen[, flags])[¶](https://docs.micropython.org/en/latest/library/collections.html#collections.deque)

    Deques (double-ended queues) are a list-like container that support O(1) appends and pops from either side of the deque. New deques are created using the following arguments:

            iterable must be the empty tuple, and the new deque is created empty.

            maxlen must be specified and the deque will be bounded to this maximum length. Once the deque is full, any new items added will discard items from the opposite end.

            The optional flags can be 1 to check for overflow when adding items.

from MP prompt:

MPY: soft reboot
MicroPython v1.22.1 on 2024-01-05; Generic ESP32 module with ESP32
Type "help()" for more information.
>>> from collections import deque
>>> b=deque([],100)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: 
>>> 

from CPython prompt:

Python 3.10.11 (C:\Program Files (x86)\Thonny\python.exe)
>>> from collections import deque
>>> b=deque([],100)
>>> 

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied