Issue #25590: Merge rlcompleter getattr change from 3.5

This commit is contained in:
Martin Panter 2015-11-13 23:48:17 +00:00
commit f4ad5f5dea
3 changed files with 21 additions and 3 deletions

View file

@ -79,6 +79,19 @@ class TestRlcompleter(unittest.TestCase):
['egg.{}('.format(x) for x in dir(str)
if x.startswith('s')])
def test_excessive_getattr(self):
# Ensure getattr() is invoked no more than once per attribute
class Foo:
calls = 0
@property
def bar(self):
self.calls += 1
return None
f = Foo()
completer = rlcompleter.Completer(dict(f=f))
self.assertEqual(completer.complete('f.b', 0), 'f.bar')
self.assertEqual(f.calls, 1)
def test_complete(self):
completer = rlcompleter.Completer()
self.assertEqual(completer.complete('', 0), '\t')