Code refactor suggestions: add properties when not in __slots__

Currently PyCharm will helpfully highlight that a given object does not have an attribute if the attribute being accessed or modified is not defined in __slots__. (Notably, the IDE won't do that if there is no __slots__ - can this be an option?) There is no refactor suggestion from that to actually add the property to __slots__. Would be great if it was possible to just say "add it to __slots__", and maybe give it a default in the __init__ method as well.

 

Sample:

class Foo(object):
__slots__ = 'prop'

f = Foo()
f.prop = 'a'
f.prop2 = 'b' # This is highlighted, but not actionable via the IDE
1

Please sign in to leave a comment.