This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ggenellina
Recipients carlj, georg.brandl, ggenellina
Date 2009-01-27.03:58:46
SpamBayes Score 0.00025151388
Marked as misclassified No
Message-id <1233028731.63.0.700534025847.issue5062@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2009-01-27 03:58:51ggenellinasetrecipients: + ggenellina, georg.brandl, carlj
2009-01-27 03:58:51ggenellinasetmessageid: <1233028731.63.0.700534025847.issue5062@psf.upfronthosting.co.za>
2009-01-27 03:58:49ggenellinalinkissue5062 messages
2009-01-27 03:58:48ggenellinacreate