Python: False positive Attribute defined outside `__init__` PYL-W0201

the Python analyzer finds a false positive PYL-W0201 for an attribute that is inherited from a base class and its value is set in a method of the parent class. Look at the example below:

from typing import Dict

class BaseClass:
    def __init__(self) -> None:
        self._subscriptions: Dict[str, str] = {}

class DerivedClass(BaseClass):
    def amethod(self) -> None:
        self._subscriptions = {}  # <--- PYL-W0201

!! Unfortunately , the error cannot be reproduced with that simplified code.
The actual error I get can be found at the link:
https deepsource dot io /gh/wasted925/deribit-v2-api/run/5a537e6e-778f-44c8-a7cb-443f1f4b52aa/python/PYL-W0201

the ‘_subscriptions’ attribute there ( line 116) is originally defined in the init() method of the base class ‘Engine’ ( line 77), however I get an Attribute defined outside __init__ error when I try to set its value there. A temporary workaround I do is to use ‘setattr’ instead.

Please have a look and let me know how I can help.


just realized false positives can be reported through the ‘ignore this occurrence’ menu. will comment there as well.