Skip to content

Commit

Permalink
Show "maxlen" in deque repr
Browse files Browse the repository at this point in the history
"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
  • Loading branch information
wjandrea authored and Carreau committed Aug 30, 2022
1 parent 4e1c56c commit 0a8b189
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions IPython/lib/pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,8 @@ def _deque_pprint(obj, p, cycle):
cls_ctor = CallExpression.factory(obj.__class__.__name__)
if cycle:
p.pretty(cls_ctor(RawText("...")))
elif obj.maxlen is not None:
p.pretty(cls_ctor(list(obj), maxlen=obj.maxlen))
else:
p.pretty(cls_ctor(list(obj)))

Expand Down

0 comments on commit 0a8b189

Please sign in to comment.