[IPython-dev] A patch to fix filename completion on Windows

Gary Bishop gb at cs.unc.edu
Thu May 22 15:55:40 EDT 2003


OK, sorry for the first one. Here is another try. I think this one

* fixes the problem
* doesn't break other cases
* and protects from other such problems
* fixes another bug.

$ diff -Naur FlexCompleter.py~ FlexCompleter.py
--- FlexCompleter.py~   2002-07-04 14:33:26.000000000 -0400
+++ FlexCompleter.py    2003-05-22 15:46:19.000000000 -0400
@@ -167,10 +167,10 @@
        #m = re.match(r"([\w\[\]]+(\.[\w\[\]]+)*)\.(\w*)", text)

         # Another option, seems to work great. Catches things like ''.<tab>
-        m = re.match(r"(\S+(\.\w+)*)\.(\w*)", text)
+        m = re.match(r"(\S+(\.\w+)*)\.(\w*)$", text)

         if not m:
-            return
+            return []
         expr, attr = m.group(1, 3)
         object = eval(expr, self.namespace)
         words = dir(object)

The change is adding a $ to the end of the regular expression for 
matching completions. It seems wrong to allow other stuff hanging off 
the end of it to be ignored. The $ requires the re to match the entire 
string. That won't happen with filenames...

The second bit is fixing a bug that is provoked by this. If the re 
doesn't match it formerly returned None but should have returned an 
empty list because that is what other code is testing for.

The net is I added 3 characters! I hope they are the right 3. See what 
you think.

gb



More information about the IPython-dev mailing list