I have I small module that I use inside one of my projects. Now I decided to place it on github so now I am writing some docstrings and cleaning the code.
I have a composition of 2 classes so the initialization looks like this:
foo = Class_1()
bar = Class_2(param1=foo)
I know that the first argument to the Class_2
has to be an instance of Class_1
or the code won't work. But it may be clear only for me as I wrote code of Class_2
, but when using module as API it may be unclear for a user that param1
has to be an instance of Class_1
. If someone will use bar = Class_2(param1='foo')
. The trackback will be bad and it will be impossible to understand what happened. So the question is: do I need to check in my __init__
that isinstance(param1, Class_1)
and if no raise an excaption with an appropriate message, or writing good documentation is enough?