Say I have a decorator which causes the function to print out any exceptions and return None, if an exception happens, instead of failing. Assuming this is a good idea, what’s the preferred naming style?
a)
@ignore_exceptions
def foobar(a, b, c):
raise ValueError("This function always fails...")
b)
@ignores_exceptions
def foobar(a, b, c):
raise ValueError("This function always fails...")
That is: should it a) be a command (the decorator tells the function to do something different), or b) a description (the decorator lets the progammer know an attribute of the function)?
I think the active version (
ignore_exceptions) is more used than the descriptive version (ignores_exceptions), at least in the Python code bases that I’m familiar with.The PEP 8 guideline does have a section on naming conventions but it does not offer much help in this case. In any case, consistency across your code base is the most important thing.