Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show "maxlen" in deque repr #13648

Merged
merged 1 commit into from Aug 30, 2022
Merged

Show "maxlen" in deque repr #13648

merged 1 commit into from Aug 30, 2022

Conversation

wjandrea
Copy link
Contributor

@wjandrea wjandrea commented Apr 23, 2022

collections.deque has a maxlen attribute that should be shown in its repr if defined, just like its default repr does.

This was brought up on Stack Overflow: https://stackoverflow.com/questions/71981214/python-deque-maxlen-does-not-show

Examples

Standard Python REPL:

>>> deque(range(10), maxlen=10)
deque([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxlen=10)

IPython:

In [2]: deque(range(10), maxlen=10)
Out[2]: deque([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

IPython after this change:

In [2]: deque(range(10), maxlen=10)
Out[2]: deque([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxlen=10)

And just to be sure, existing behaviour is unchanged if no maxlen is provided or the deque is recursive:

In [3]: deque(range(10))
Out[3]: deque([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

In [4]: dq = deque(range(10), maxlen=10)

In [5]: dq.append(dq)

In [6]: dq
Out[6]: deque([1, 2, 3, 4, 5, 6, 7, 8, 9, deque(...)], maxlen=10)

P.S. LMK if this change requires adding a test or a whatsnew entry, or anything else.

"collections.deque" has a "maxlen" attribute that should be shown in its repr if defined, just like its default repr does.

This was brought up on Stack Overflow: https://stackoverflow.com/questions/71981214/python-deque-maxlen-does-not-show
@Carreau
Copy link
Member

Carreau commented Aug 30, 2022

Thanks, that seem reasonable.

@Carreau Carreau merged commit ae639fb into ipython:main Aug 30, 2022
@Carreau Carreau added this to the 8.5 milestone Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants