Strange tab completion oddity with enums?

Peter Otten __peter__ at web.de
Mon Oct 7 04:11:12 EDT 2019


Chris Angelico wrote:

>> Looks like everything starting with an underscore (except class, doc, and
>> module) is suppressed, probably to suppress some noise...
>>
> 
> That's why dir() shows what it does, but tab completion seems to have
> some other source, as it's able to find a lot of other attributes but
> not __annotations__. Very strange.

If I'm reading rlcompleter.py correctly 

        words = set(dir(thisobject))
        words.discard("__builtins__")

        if hasattr(thisobject, '__class__'):
            words.add('__class__')
            words.update(get_class_members(thisobject.__class__))

def get_class_members(klass):
    ret = dir(klass)
    if hasattr(klass,'__bases__'):
        for base in klass.__bases__:
            ret = ret + get_class_members(base)
    return ret

it implements its own way to walk the class tree, and type being the base 
class of EnumMeta those additional attributes should be the result of

dir(type)




More information about the Python-list mailing list