This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: let linter allow defining attribute outside __init__ if called in __init__
Type: behavior Stage: resolved
Components: Parser Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: lys.nikolaou, ohadsunny, pablogsal
Priority: normal Keywords:

Created on 2021-05-13 10:00 by ohadsunny, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg393568 - (view) Author: Ohad Shemesh (ohadsunny) Date: 2021-05-13 10:00
A have a simple scenario in which I have a class with some initialized attribute that I want to be able to reset again. 
In order to avoid code duplication I'd to to something like this - 

class A:
    def __init__(self):
        self.reset()

    def reset(self):
        self.ls: List[datetime] = []

However this behavior makes the linter (in my case in pycharm) say "instance attribute defined outside __init__".
I think it'd be for the better if the linter allows this kind of definition if the function (i.e reset) is called in __init__.
msg393573 - (view) Author: Lysandros Nikolaou (lys.nikolaou) * (Python committer) Date: 2021-05-13 11:43
Hi Ohad and thanks for filing a report.

This is not a problem with CPython and outside of our control. You'd have to ask this question to the PyCharm linter team (unfortunately I don't know where exactly you would be able to do that).

Closing.
History
Date User Action Args
2022-04-11 14:59:45adminsetgithub: 88288
2021-05-13 11:43:52lys.nikolaousetstatus: open -> closed
resolution: not a bug
messages: + msg393573

stage: resolved
2021-05-13 10:00:26ohadsunnycreate