mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
bpo-35664: Optimize operator.itemgetter (GH-11435)
This commit is contained in:
parent
3f7983a25a
commit
2d53bed79c
3 changed files with 54 additions and 5 deletions
|
@ -401,6 +401,19 @@ class OperatorTestCase:
|
|||
self.assertEqual(operator.itemgetter(2,10,5)(data), ('2', '10', '5'))
|
||||
self.assertRaises(TypeError, operator.itemgetter(2, 'x', 5), data)
|
||||
|
||||
# interesting indices
|
||||
t = tuple('abcde')
|
||||
self.assertEqual(operator.itemgetter(-1)(t), 'e')
|
||||
self.assertEqual(operator.itemgetter(slice(2, 4))(t), ('c', 'd'))
|
||||
|
||||
# interesting sequences
|
||||
class T(tuple):
|
||||
'Tuple subclass'
|
||||
pass
|
||||
self.assertEqual(operator.itemgetter(0)(T('abc')), 'a')
|
||||
self.assertEqual(operator.itemgetter(0)(['a', 'b', 'c']), 'a')
|
||||
self.assertEqual(operator.itemgetter(0)(range(100, 200)), 100)
|
||||
|
||||
def test_methodcaller(self):
|
||||
operator = self.module
|
||||
self.assertRaises(TypeError, operator.methodcaller)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue