Issue 18903: IDLE file-completion is case-sensitive in Windows (original) (raw)
Created on 2013-09-02 01:33 by westley.martinez, last changed 2022-04-11 14:57 by admin.
Messages (9)
Author: Westley Martínez (westley.martinez) *
Date: 2013-09-02 01:33
Hi, I'm not sure if this would be considered a bug or a feature request, but IDLE's file-completion is case-sensitive in Windows (e.g. if I have a file named ABBA and I type in 'abb' + tab, ABBA won't pop up. Since Windows files systems are not case-sensitive, it might make sense for the file-completion to disregard case as well. I'm not sure if this behaviour is preferred, however, so I'll leave that up for discussion.
I tested the behaviour on 3.3 and 3.4; I assume it's the same for other versions as well.
Author: Terry J. Reedy (terry.reedy) *
Date: 2013-09-06 19:07
This strikes me a sort-of a bug. However, feature vs. bug does not matter for small changes (see PEP434). Is Windows the only case preserving, case insensitive OS?
Author: Westley Martínez (westley.martinez) *
Date: 2013-09-07 16:59
I believe HFS is case-preserving as well, but it also can be configured to be case-sensitive. I'm not a Mac owner though so don't take my word for it.
Author: Terry J. Reedy (terry.reedy) *
Date: 2013-09-08 11:54
A possible complication is that at least in part, the same code (AutoComplete.py) is used for both attribute completion and filename completion. Attribute completion is always case sensitive.
Author: Terry J. Reedy (terry.reedy) *
Date: 2013-09-08 22:19
The initial difficulty I am having is that the edit menu, help file, code, and behavior do not seem to match up, so this whole feature set needs more review. For one thing, the AutoCompleteWindow (ACW) often comes up empty initially. Sometimes it fills in a couple of seconds later, sometimes not. Or it only fills in if I enter or delete a char.
However, I did manage to reproduce the issue. (Westley, your ambiguous report cannot be exactly correct. If you typed 3 chars (no quotes) and tab, you should get a list of python names, not filenames. If you typed 5 chars (two quotes) and tab, you should get a literal tab. You would have to type 4 chars (open quote only) and tab to get filenames.)
Reviewing the code, I see the following. AutoComplete.open_completions calls .fetch_completions to get a sorted list of possible completions, according to the mode. It then makes an ACW and calls .show_window. ACW.show_window receives the mode and stores it as self.mode. That is used in the logic of ACW.keypress_event for handling 'special' characters. It is currently not used for matching normal characters to completions. ACW.show_window also allocates a tk.Listbox with self.listbox = listbox = Listbox(acw, yscrollcommand=scrollbar.set, exportselection=False, bg="white") As near as I can tell, the matching of what the user types with entries in the ACW listbox is done in ACS._binary_search as items in the listbox seem to be set with self.listbox.select_set(self._binary_search(self.start))
For this issue, we need two things.
.fetch_completions should sort filenames disregarding case on Windows. Perhaps key = str.lower will be sufficient, but I do not know what 'case-insensitive' actually means on Windows with respect to general Unicode file names.
A case-insensitive version of _binary_search -- perhaps an instance function (closure) defined in .show_window using a list of lower-cased entries. Both the original and replacement should probably use the bisect module, which has a C accelerator.
There is a third thing: tests. I am reluctant to continue patching Idle without tests for the issue, but writing one for this will probably be harder than the patch itself. My main concern is not to make things worse.
It would to easier to document that one should start with one letter and if there is no desired match, backspace and try the other case ;-).
Author: Westley Martínez (westley.martinez) *
Date: 2013-09-09 00:33
My example was totally abstract and untested. Sorry for any confusion.
After doing some research, I find that this issue is complicated further: http://support.microsoft.com/kb/100625
I think we can assume that running into a situation where there are identical filenames except for case is quite rare. The thing is, I don't even know how to make files like this on Windows. Explorer doesn't work, and other Win32 apps won't do it (they all spit up errors). I reckon I can do it with Python or some other language, since I assume they does these things at a low level.
I'll start looking at the code and see if I can come up with a patch. My aim is to make it similar enough to how the Windows Terminal does it, (i.e. it corrects the typed name to the proper case) since that is what I'd imagine most Windows programmers are used to.
Author: Westley Martínez (westley.martinez) *
Date: 2013-09-10 07:51
I've written a patch that sort of implements the functionality that makes the most sense to me. The problem is it only works right for the first entry. It's kind of wonky and I'm not entirely sure how it behaves, nor do I know the cause of the bug, but it's a start.
Author: Mark Lawrence (BreamoreBoy) *
Date: 2014-10-03 21:04
@Terry can you comment on Westley's patch please.
Author: Terry J. Reedy (terry.reedy) *
Date: 2014-10-05 02:49
Wesley himself suggested that it is not ready to apply. There are currently 7 completion issues for Idle. I hope to someday work on all of them together, alone with a test file. But there are a couple of other issue clusters that I consider higher priority.
History
Date
User
Action
Args
2022-04-11 14:57:50
admin
set
github: 63103
2020-06-08 01:00:06
terry.reedy
set
versions: + Python 3.10, - Python 3.6, Python 3.7
2017-06-30 00:51:32
terry.reedy
set
nosy: - BreamoreBoy
2017-06-30 00:51:20
terry.reedy
set
assignee: terry.reedy
versions: + Python 3.6, Python 3.7, - Python 2.7, Python 3.4, Python 3.5
2014-10-05 02:49:12
terry.reedy
set
stage: needs patch -> patch review
messages: +
versions: + Python 2.7
2014-10-03 21:04:07
BreamoreBoy
set
nosy: + BreamoreBoy
messages: +
versions: + Python 3.5, - Python 3.3
2013-09-10 07:51:10
westley.martinez
set
files: + cpython-idle-18903-1.patch
keywords: + patch
messages: +
2013-09-09 00:33:35
westley.martinez
set
messages: +
2013-09-08 22:19:24
terry.reedy
set
messages: +
stage: needs patch
2013-09-08 11:54:57
terry.reedy
set
messages: +
2013-09-07 16:59:58
westley.martinez
set
messages: +
2013-09-06 19:07:41
terry.reedy
set
nosy: + terry.reedy
messages: +
2013-09-02 01:33:35
westley.martinez
create