There's also the pattern with functools.partial that allows you to call decorators with optional arguments without the parenthesis if you want to use the default values.
Now you can apply the decorator without the parenthesis if you want to use the default value.
@print_resultdefadd(a,b):returna+badd(2,3)# outputs '5'@print_result()defadd(a,b):returna+badd(2,3)# outputs '5'@print_result(prefix='The return value is ')defadd(a,b):returna+badd(2,3)# outputs 'The return value is 5'
There's no way of getting it wrong when you apply the decorator. IMO it's the simplest and most readable pattern. I use it all the time.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
There's also the pattern with
functools.partial
that allows you to call decorators with optional arguments without the parenthesis if you want to use the default values.Now you can apply the decorator without the parenthesis if you want to use the default value.
There's no way of getting it wrong when you apply the decorator. IMO it's the simplest and most readable pattern. I use it all the time.