Which coding-style is better / correct and why? Using assert statement in each function:
def fun_bottom(arg):
assert isinstance(arg, int)
#blah blah
def fun_middle(arg):
assert isinstance(arg, int)
fun_bottom(arg)
#blah blah
def fun_top(arg):
assert isinstance(arg, int)
fun_middle(arg)
#blah blah
Or, because we know that type of arg is checked in fun_bottom function, just omit assertions in fun_middle and fun_top? Or maybe there's another solution?
EDIT #1
Ouch, I was misunderstood. I just used assert isinstance(arg, int) as an example. I'll rewrite the question:
Which one to use:
Option 1: Check if argument fulfil function's requirements in each function:
def fun_bottom(arg):
assert arg > 0
#blah blah
def fun_middle(arg):
assert arg > 0
fun_bottom(arg)
#blah blah
def fun_top(arg):
assert arg > 0
fun_middle(arg)
#blah blah
Option 2: Because we know that argument is checked in bottom-most function, we make no assertions in middle- and top- functions:
def fun_bottom(arg):
assert arg > 0
#blah blah
def fun_middle(arg):
fun_bottom(arg)
#blah blah
def fun_top(arg):
fun_middle(arg)
#blah blah
try/except, then do whatever you need to do with it.__debug__is turned off). If you need to do explicit value/type/whatever checking, do it explicitly. Otherwise, just puttryandexceptaround things that you expect might fail.