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
Fix: Add custom repr to pretty print collections.UserList #13320
Conversation
IPython/lib/pretty.py
Outdated
if cycle: | ||
p.pretty(cls_ctor(RawText("..."))) | ||
else: | ||
p.pretty(cls_ctor(list(obj))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this meant we recreate the list rather than accessing UserList.data
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a small optimisation, not sure it is worth it, though the current implementation is identical to _deque_pprint, so we should either reuse _deque_pprint
or use obj.data
. Up to you.
- a test would indeed be good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Carreau Thanks for the input. I'll start working on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Carreau I have updated _userlist_pprint
with obj.data
for optimization and added test for the same in lib/tests/test_pretty.py
. All tests have passed. ✔️
Please Review.
Is this tested anywhere in regression? |
IPython/lib/pretty.py
Outdated
if cycle: | ||
p.pretty(cls_ctor(RawText("..."))) | ||
else: | ||
p.pretty(cls_ctor(list(obj))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a small optimisation, not sure it is worth it, though the current implementation is identical to _deque_pprint, so we should either reuse _deque_pprint
or use obj.data
. Up to you.
- a test would indeed be good.
416621c
to
55856cb
Compare
… lists. -implemented _userlist_pprint , in accordance with pprint of other container types of collections module.
- all tests passed
63e98d9
to
aca50d2
Compare
Implemented
_userlist_pprint
to enable pretty printing ofcollections.UserList
.Followed convention of previously implemented pprints of other container types of the collections module.
solved against issue #13283
Eg Usage: