Skip to content

Commit 833c0a1

Browse files
authored
Merge pull request #154 from kessido/master
fixed coll_repr printing incorrectly when max_n!=10, and added relevant tests
2 parents 40eb135 + d193932 commit 833c0a1

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

fastcore/foundation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def docs(cls):
8686
def coll_repr(c, max_n=10):
8787
"String repr of up to `max_n` items of (possibly lazy) collection `c`"
8888
return f'(#{len(c)}) [' + ','.join(itertools.islice(map(repr,c), max_n)) + (
89-
'...' if len(c)>10 else '') + ']'
89+
'...' if len(c)>max_n else '') + ']'
9090

9191
# Cell
9292
def is_bool(x):

nbs/02_foundation.ipynb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@
613613
"def coll_repr(c, max_n=10):\n",
614614
" \"String repr of up to `max_n` items of (possibly lazy) collection `c`\"\n",
615615
" return f'(#{len(c)}) [' + ','.join(itertools.islice(map(repr,c), max_n)) + (\n",
616-
" '...' if len(c)>10 else '') + ']'"
616+
" '...' if len(c)>max_n else '') + ']'"
617617
]
618618
},
619619
{
@@ -631,7 +631,10 @@
631631
"metadata": {},
632632
"outputs": [],
633633
"source": [
634-
"test_eq(coll_repr(range(1000)), '(#1000) [0,1,2,3,4,5,6,7,8,9...]')"
634+
"test_eq(coll_repr(range(1000)), '(#1000) [0,1,2,3,4,5,6,7,8,9...]')\n",
635+
"test_eq(coll_repr(range(1000), 5), '(#1000) [0,1,2,3,4...]')\n",
636+
"test_eq(coll_repr(range(10), 5), '(#10) [0,1,2,3,4...]')\n",
637+
"test_eq(coll_repr(range(5), 5), '(#5) [0,1,2,3,4]')"
635638
]
636639
},
637640
{

0 commit comments

Comments
 (0)