8000 Representation of datastructures:List · nirum-lang/nirum-python@6b4098e · GitHub
[go: up one dir, main page]

Skip to content

Commit 6b4098e

Browse files
author
Chang-soo Han
committed
Representation of datastructures:List
1 parent dd3d2b0 commit 6b4098e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

nirum/datastructures.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ def index(self, item):
7474
def count(self, item):
7575
return self.items.count(item)
7676

77+
def __repr__(self):
78+
args = repr(self.items)
79+
return '{0.__module__}.{0.__name__}({1})'.format(type(self), args)
80+
7781

7882
map_type = Map
7983
list_type = List

tests/datastructures_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,9 @@ def test_list_immutable():
9797
assert immutable_list.items != mutable_list
9898
assert immutable_list.items == [1, 2]
9999
assert mutable_list == [1, 2, 3]
100+
101+
102+
def test_list_repr():
103+
assert repr(List([])) == 'nirum.datastructures.List([])'
104+
assert repr(List([1])) == 'nirum.datastructures.List([1])'
105+
assert repr(List([1, 2])) == 'nirum.datastructures.List([1, 2])'

0 commit comments

Comments
 (0)
0