Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 43c7193

Browse files
007vedantCarreau
authored andcommitted
Added custom pprint to pretty print collections.UserList like regular lists.
-implemented _userlist_pprint , in accordance with pprint of other container types of collections module.
1 parent e343cd4 commit 43c7193

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

IPython/lib/pretty.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,10 +920,20 @@ def _counter_pprint(obj, p, cycle):
920920
else:
921921
p.pretty(cls_ctor())
922922

923+
924+
def _userlist_pprint(obj, p, cycle):
925+
cls_ctor = CallExpression.factory(obj.__class__.__name__)
926+
if cycle:
927+
p.pretty(cls_ctor(RawText("...")))
928+
else:
929+
p.pretty(cls_ctor(list(obj)))
930+
931+
923932
for_type_by_name('collections', 'defaultdict', _defaultdict_pprint)
924933
for_type_by_name('collections', 'OrderedDict', _ordereddict_pprint)
925934
for_type_by_name('collections', 'deque', _deque_pprint)
926935
for_type_by_name('collections', 'Counter', _counter_pprint)
936+
for_type_by_name("collections", "UserList", _userlist_pprint)
927937

928938
if __name__ == '__main__':
929939
from random import randrange

0 commit comments

Comments
 (0)