Title: rlcompleter.Completer has duplicate matches
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.4, Python 3.5, Python 2.7
Status: closed Resolution: out of date
Dependencies: Superseder: tab-completition on instances repeatedly accesses attribute/descriptors values
View: 25590
Assigned To: Nosy List: Claudiu.Popa, donlorenzo, ezio.melotti, martin.panter
Priority: normal Keywords: patch

Created on 2014-08-05 16:13 by donlorenzo, last changed 2016-05-13 12:39 by martin.panter. This issue is now closed.

File name Uploaded Description Edit
rlcompleter.diff donlorenzo, 2014-08-05 16:13 collect possible match words in a set instead of a list
rlcompleter_22143.patch donlorenzo, 2014-10-29 13:51 fix + test
rlcompleter_22143.patch donlorenzo, 2014-10-30 13:34 fix + test (using assertIn and assertIsNone)
Messages (10)
msg224852 - (view) Author: Lorenz Quack (donlorenzo) * Date: 2014-08-05 16:13
>>> import rlcompleter
>>> completer = rlcompleter.Completer()
>>> class A(object):
...     foo = None
>>> class B(A):
...     pass
>>> b = B()
>>> print([completer.complete("", i) for i in range(4)])
['', '', '', None]

I would expect the completions to be unique.
This happens because the possible words to match are put into a list.
A possible fix is putting them into a set instead.
Patch attached.
msg227592 - (view) Author: PCManticore (Claudiu.Popa) * (Python triager) Date: 2014-09-26 07:54
The patch looks good. Could you add a test?
msg230209 - (view) Author: Lorenz Quack (donlorenzo) * Date: 2014-10-29 13:51

here finally the updated patch with test case.
It depends on and should be applied after the patch included in issue22141.

This patch does changes two things:
1) completions are now unique
2) completions are now in no specific order

I had to touch some other rlcompleter tests because they assumed a certain order of the returned matches.

Thanks for reviewing!
msg230269 - (view) Author: PCManticore (Claudiu.Popa) * (Python triager) Date: 2014-10-30 13:03
I don't know why there's no review link for your patch. Anyway..

+        self.assertTrue(c.complete("", 0) in ['', 'A.foobar('])
+        self.assertTrue(c.complete("", 1) in ['', 'A.foobar('])

You can use self.assertIn for these.

+        self.assertEqual(c.complete("", 1), None)


Otherwise, the patch looks good to me.
msg230270 - (view) Author: Lorenz Quack (donlorenzo) * Date: 2014-10-30 13:34
Thanks for reviewing!

test now use assertIn and assertIsNone as suggested

PS: My Contributors Agreement is in progress. Just emailed the PSF with some question (but I intend to sign it)
msg230356 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2014-10-31 17:04
+        return list(set(matches))

Shouldn't this be sorted before being returned?
msg230376 - (view) Author: Lorenz Quack (donlorenzo) * Date: 2014-10-31 18:53
I couldn't find anything concerning order in the docs so I didn't see any reason the have them sorted.
I'm not opposed to sorting them. I guess you could call me +0 on returning sorted(set(matches))
msg236419 - (view) Author: Lorenz Quack (donlorenzo) * Date: 2015-02-22 22:52
sorry it took so long but my contributor agreement is now signed.

Do you want me to write a patch with the results sorted?
If so, should I also change the docs to reflect that the results are sorted? This would then also affect other implementations because they would be required to also return sorted results.
msg265470 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-05-13 12:28
I think this was fixed by Issue 25663. (Sorry I wasn’t aware of the work already done here.)
msg265471 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-05-13 12:39
Actually more like Issue 25590 (this was about attribute names, not global names)
Date User Action Args
2016-05-13 12:39:24martin.pantersetsuperseder: Make rlcompleter avoid duplicate global names -> tab-completition on instances repeatedly accesses attribute/descriptors values
messages: + msg265471
2016-05-13 12:28:37martin.pantersetstatus: open -> closed

nosy: + martin.panter
messages: + msg265470

superseder: Make rlcompleter avoid duplicate global names
resolution: out of date
2015-02-22 22:52:24donlorenzosetmessages: + msg236419
2014-10-31 18:53:12donlorenzosetmessages: + msg230376
2014-10-31 17:04:40ezio.melottisetmessages: + msg230356
2014-10-30 13:34:32donlorenzosetfiles: + rlcompleter_22143.patch

messages: + msg230270
2014-10-30 13:03:38Claudiu.Popasetmessages: + msg230269
2014-10-29 13:51:52donlorenzosetfiles: + rlcompleter_22143.patch

messages: + msg230209
2014-09-26 07:54:27Claudiu.Popasetnosy: + Claudiu.Popa
messages: + msg227592
2014-08-05 16:17:27ezio.melottisetnosy: + ezio.melotti
stage: patch review
type: behavior

versions: - Python 3.1, Python 3.2, Python 3.3
2014-08-05 16:13:15donlorenzocreate