mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
Issue #10160: Speed up operator.attrgetter. Patch by Christos Georgiou.
This commit is contained in:
parent
65b4af34d7
commit
e974571d36
4 changed files with 112 additions and 30 deletions
|
@ -275,8 +275,7 @@ class OperatorTestCase(unittest.TestCase):
|
|||
self.assertEqual(f(a), 'arthur')
|
||||
f = operator.attrgetter('rank')
|
||||
self.assertRaises(AttributeError, f, a)
|
||||
f = operator.attrgetter(2)
|
||||
self.assertRaises(TypeError, f, a)
|
||||
self.assertRaises(TypeError, operator.attrgetter, 2)
|
||||
self.assertRaises(TypeError, operator.attrgetter)
|
||||
|
||||
# multiple gets
|
||||
|
@ -285,7 +284,7 @@ class OperatorTestCase(unittest.TestCase):
|
|||
record.y = 'Y'
|
||||
record.z = 'Z'
|
||||
self.assertEqual(operator.attrgetter('x','z','y')(record), ('X', 'Z', 'Y'))
|
||||
self.assertRaises(TypeError, operator.attrgetter('x', (), 'y'), record)
|
||||
self.assertRaises(TypeError, operator.attrgetter, ('x', (), 'y'))
|
||||
|
||||
class C(object):
|
||||
def __getattr__(self, name):
|
||||
|
@ -304,6 +303,10 @@ class OperatorTestCase(unittest.TestCase):
|
|||
self.assertEqual(f(a), ('arthur', 'thomas'))
|
||||
f = operator.attrgetter('name', 'child.name', 'child.child.name')
|
||||
self.assertRaises(AttributeError, f, a)
|
||||
f = operator.attrgetter('child.')
|
||||
self.assertRaises(AttributeError, f, a)
|
||||
f = operator.attrgetter('.child')
|
||||
self.assertRaises(AttributeError, f, a)
|
||||
|
||||
a.child.child = A()
|
||||
a.child.child.name = 'johnson'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue