Autocomplete popup for MetaClass objects
Answered
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 @classmethod def init_objects(cls, count): for x in range(count): obj = cls() cls.objects.append(obj) 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
Please sign in to leave a comment.
Hi,
I've reported it to our issue tracker https://youtrack.jetbrains.com/issue/PY-38805, please vote for it and follow for updates.