You could even do something like


    def apply(self, p, expr, n, evaluation):
        'Operate[p_, expr_, Optional[n_, 1]]'
 
        head_depth = n.to_python()
        if head_depth is None:
            return evaluation.message(...)
        # head_depth is now a python int
        if head_depth < 0: