Some point,decorators within decorators with several argument is confusing for most.
I know well how it works,but can really struggle if i haven't look it at for a while.
Graham Dumpleton author of wrapt: Hear no evil, see no evil.
David Beazley Decorators with Arguments.
Decorators can be useful,two of my favorite Python packages use decorator Flask and Click .
I used Click in my tutorial here
So the user interface get clean by hiding all code that's not needed to be shown,
like cheeking for path with
This also mean that i don't have to write error checking for
I know well how it works,but can really struggle if i haven't look it at for a while.
(Mar-28-2018, 05:28 PM)wavic Wrote: If you have any docstrings in the decorated function you will lose it. See functools.wrapsYes this is important,also wrapt take this further.
Graham Dumpleton Wrote:The wrapt module focuses very much on correctness.So if i should done anything serious with decorator today i would look into using wrapt
It therefore goes way beyond existing mechanisms such asfunctools.wraps()
to ensure that decorators preserve introspectability,
signatures, type checking abilities etc.
Graham Dumpleton author of wrapt: Hear no evil, see no evil.
David Beazley Decorators with Arguments.
Decorators can be useful,two of my favorite Python packages use decorator Flask and Click .
I used Click in my tutorial here
So the user interface get clean by hiding all code that's not needed to be shown,
like cheeking for path with
type=click.Path(exists=True)
.This also mean that i don't have to write error checking for
Path
in my code.@click.command() @click.argument('file', type=click.Path(exists=True), metavar='<file>') def play(file): ....