Message80615
This is not a bug in rlcompleter; __dir__ is returning bogus items, and
rlcompleter checks whether there exist actually an attribute with such
name.
Defining __getattr__ (or __getattribute__) and a matching __dir__ works
fine:
>>> class B(object):
... def __dir__(self):
... return dir(object) + ["xa","xb","xc"]
... def __getattr__(self, name):
... if name in ["xa","xb","xc"]:
... return None
... raise AttributeError, name
...
>>> b = B()
>>> import rlcompleter
>>> c = rlcompleter.Completer()
>>> c.complete("b.", 0)
'b.__class__('
>>> c.matches
['b.__class__(', 'b.__delattr__(', 'b.__doc__', 'b.__format__(',
'b.__getattribute__(',
...
'b.xa', 'b.xb', 'b.xc', 'b.__class__(', 'b.__class__(',
...]
>>> c.complete("b.x", 0)
'b.xa'
>>> c.matches
['b.xa', 'b.xb', 'b.xc']
Now, looking at this I saw there *is* a bug in rlcompleter, as it may
return many duplicate items:
>>> c.complete("b.__c", 0)
'b.__class__('
>>> c.matches
['b.__class__(', 'b.__class__(', 'b.__class__(', 'b.__class__(']
The attached patch fixes that. |
|
Date |
User |
Action |
Args |
2009-01-27 03:58:51 | ggenellina | set | recipients:
+ ggenellina, georg.brandl, carlj |
2009-01-27 03:58:51 | ggenellina | set | messageid: <1233028731.63.0.700534025847.issue5062@psf.upfronthosting.co.za> |
2009-01-27 03:58:49 | ggenellina | link | issue5062 messages |
2009-01-27 03:58:48 | ggenellina | create | |
|