rlcompleter not calling __getattr__ on [ ]
Jaco Schieke
wortelslaai at yahoo.com
Mon Apr 22 13:19:53 EDT 2002
Fernando Pérez <fperez528 at yahoo.com> wrote in message news:<a9mv1o$7jh$1 at peabody.colorado.edu>...
> Jaco Schieke wrote:
>
> > Being new to interactive python, I have the problem that rlcompleter
> > does not seem to be able to resolve the items in a list:
> >
> > This works as expected:
> > ======================================
> >>>> import readline, atexit, rlcompleter
> >>>> readline.parse_and_bind('tab: complete')
> >>>> a=[[],"",1]
> >>>> a.<tab>
> > a.append a.count a.extend a.index a.insert a.pop
> > a.remove a.reverse a.sort
> >
> >
> > Now is this also supposed to work?
> > ==================================
> >>>> a[0].<tab>
> > . .. <---- this is the output I receive
> > instead of the properties of an []
> >
> >
> > 'cause this works:
> > ==================================
> >>>> b=a[0]
> >>>> b.<tab>
> > b.append b.count b.extend b.index b.insert b.pop
> > b.remove b.reverse b.sort
>
> I was going to ask the same thing as I'm inclined to think this is a bug:
> readline has '[' and ']' as part of its internal list of word delimiters, so
> when you do
> a[0].<tab>
> it breaks the word at ']' and sees a bare '.', hence the completions you get.
> So far so good.
>
> BUT: if you change the list of delimiters (with readline.set_delimiters()) to
> remove '[' and ']', the problem persists. That's the part I think to be a bug
> (I could be wrong, but I'd like to understand why if that's the case). At
> this point it shouldn't break at ']' anymore, and the completion should be
> done on the full 'a[0]'. I put print statements in the rlcompleter code to
> see this and indeed, readline _is_ breaking on ']' even after removing the
> character from the list of delimiters.
>
> Unfortunately the completion code is in C and I don't have the sources around,
> so I haven't had the chance to take a look at this.
>
> I'd love to hear from someone who knows the code as to this behavior really is
> a bug or not before shooting off to SF and looking like an idiot :)
>
> Cheers,
>
> f.
Looks like the regexp in rlcompleter that searches the string does not
work correctly. After changing the line
> m = re.match(r"(\w+(\.\w+)*)\.(\w*)", text)
to
> m = re.match(r"([\w\[\]]+(\.[\w\[\]]+)*)\.(\w*)", text)
it matched on the brackets too and could get to the objects. I also
had to change the delimiters to exclude [].
More information about the Python-list
mailing list