Monday, 24 August 2020

Is it possible to have Python IDEs offer autocompletion for dynamically generated class attributes?

Are there any tricks I can employ to get IDEs to offer code completion for dynamically generated class attributes? For instance


class A:
    
    def __init__(self):
        setattr(self, "a", 5)

This code will set the class attribute of A called a to the value of 5. But IDEs do not know about a and therefore you do not get code completion for it. I've read that the __dir__ method can be hooked, but the suggestion made in that answer has not worked for me. Does anybody have any ideas?



from Is it possible to have Python IDEs offer autocompletion for dynamically generated class attributes?

No comments:

Post a Comment