My task is to rewrite app written in Java using Python. It is my first contact with Python and I'm a bit confused. As I read, Python is not strongly typed. In my program I have a lot of classes with methods with parameters which are instances of other classes. Here is a short demo:
class ClassA:
nameOfClass = "ClassA"
def __init__(self):
print("I'm ClassA")
def printOtherClassMethod(self, instanceOfOtherClass):
instanceOfOtherClass.printThisMethod()
class ClassB:
nameOfClass = "ClassA"
def __init__(self):
print("I'm ClassB")
def printThisMethod(self):
print("How classA can know that printThisMethod exists?")
classA = ClassA()
classB = ClassB()
classA.printOtherClassMethod(classB)
Is there any way to specify that argument of printOtherClassMethod
must be instance of ClassB
? The first problem is that my IDE (PyCharm) can't detect that instanceOfOtherClass
has printThisMethod
and it is very easy to make mistake. Additionally, I have a practise to have each class in the individual file. I'm afraid of importing particular files. For example if ClassA
and ClassB
would be in individual files should I import ClassB
in file of ClassA
? My tests show that not, but I want to avoid milions of exceptions and error in the future.