Skip to content

Commit 6ee3a52

Browse files
committed
-
1 parent 1a79223 commit 6ee3a52

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

source_py3/python_toolbox/combi/perming/perm.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,15 @@ def unrapplied(self):
236236
)
237237

238238
def __getitem__(self, i):
239-
i_to_use = self.domain.index(i) if self.is_dapplied else i
239+
if self.is_dapplied:
240+
try:
241+
i_to_use = self.domain.index(i)
242+
except TypeError:
243+
# Some types, like `str`, annoyingly raise `TypeError` instead
244+
# of `IndexError`.
245+
raise IndexError
246+
else:
247+
i_to_use = i
240248
return self._perm_sequence[i_to_use]
241249

242250
length = property(

source_py3/test_python_toolbox/test_combi/test_perm_space.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,16 @@ def test_dapplied_perm_space():
267267
'''<Perm: ('g', 'r', 'o', 'w', 'l') => (4, 3, 2, 1, 0)>'''
268268

269269
assert dapplied_perm.index(4) == 'g'
270-
270+
271271
assert dapplied_perm.as_dictoid['g'] == 4
272272
assert dapplied_perm.items[0] == ('g', 4)
273273

274+
with cute_testing.RaiseAssertor(IndexError):
275+
dapplied_perm[2]
276+
with cute_testing.RaiseAssertor(IndexError):
277+
dapplied_perm.as_dictoid[2]
278+
with cute_testing.RaiseAssertor(ValueError):
279+
dapplied_perm.index('x')
274280

275281
# `__contains__` works on the values, not the keys:
276282
for char in 'growl':

0 commit comments

Comments
 (0)