Autocomplete popup for MetaClass objects


Hello, Pycharm/IDEAU python autocomplete question. There is a sample code:

class MetaClass(type):
    def __init__(cls, name, bases, attrs):
        cls.objects = []

class BasicClass:
    __metaclass__ = MetaClass

    def init_objects(cls, count):
        for x in range(count):
            obj = cls()

class RealClass(BasicClass):
def hint_me(self):
print('hint me')
RealClass.init_objects(3) # hint_me() should be in autocomplete pop-up when typing RealClass.objects[0].hint_me()

Short explanation:

I have BasicClass with common method init_objects that creates number of instances and append them to the MetaClass objects list, so each inherited class from BasicClass (like RealClass) will have their own list of objects. But there is a problem with hints of these objects in the list, it doesn't show hint_me() or other class methods when typing "RealClass.objects[0].".

Adding """@type : list of BasicClass""" to MetaClass after line: cls.objects = [] works, but it only shows methods from BasicClass, not inherited (and """@type : list of cls""" doesn't work at all).

Any ideas how to make it work? Thanks

1 comment
Comment actions Permalink


I've reported it to our issue tracker, please vote for it and follow for updates.


Please sign in to leave a comment.