jeudi 20 septembre 2018

Python pattern for keeping default arguments of subfunction

Suppose I have a function with a default argument and another function calling it. I want to let the caller either override the default argument or keep it. I've fallen into the following pattern. Is this an antipattern, is this best practices, is there a better way?

def subfunc(x=10):
    # do something with x

def callingfunc(x=None):
    y= subfunc() if x is None else subfunc(x) # IS THIS AN ANTI PATTERN?

Aucun commentaire:

Enregistrer un commentaire