There are three classes (A, B, C). Class A is master and works with some data from classes B and C. Class B works with data from class C, and an instance of class C is passed to B via A.
The code for the example is below ()
a.py
from b import SomeB
from c import SomeC
class SomeA(object):
def __init__(self):
self.object_c = SomeC()
self.object_b = SomeB(self.object_c)
self.some_work_with_obj_c_data()
self.some_work_with_obj_b_data()
def some_work_with_obj_c_data(self):
self.object_c.some_var_for_a += 1
print(self.object_c.some_var_for_a)
def some_work_with_obj_b_data(self):
self.object_b.some_var_for_a += 1
print(self.object_b.some_var_for_a)
if __name__ == "__main__":
object_a = SomeA()
b.py
class SomeB(object):
def __init__(self, object_c_from_a):
self.some_var_for_a = 5678
self.object_c_from_a = object_c_from_a # an instance of the SomeC class from C.py
self.some_work_with_obj_c_data()
def some_work_with_obj_c_data(self):
self.object_c_from_a.some_var_for_b += 1
print(self.object_c_from_a.some_var_for_b)
c.py
class SomeC(object):
def __init__(self):
self.some_var_for_b = 1234
self.some_var_for_a = 4321
In the real case it is two GUI windows (A and B), and some data handler (C).
Essentially, class B doesn't explicitly specify what type of data we're working with (especially if you don't specify with a comment). Also there is no autocomplete code in the IDE (PyCharm for example).
Is there a mechanism for specifying that a variable is a reference to an instance of a particular class? Or there's a more global architecture problem and it shouldn't exist in principle?