In object-oriented programming it’s up to the developer to ensure an object is always in a consistent state after instantiation and after a method finishes. Other than that you’re free to develop the class as you wish (keeping in mind certain principles with subclassing / overriding and so on).
A tool such as Pylint will warn when you’re setting instance variables outside __init__
. It can be argued that setting all instance variables in the __init__
is cleaner but it’s not a rule that must be abided by at all times.