What is wrong this wrapper (decorator)?

Gregory Ewing greg.ewing at canterbury.ac.nz
Mon Nov 16 01:30:54 EST 2015


fl wrote:
> wrapper(sub(two, one))
> Out[38]: <function checker>

This doesn't do what you probably meant it to do.
It first calls sub() with arguments one and two, and
then passes the result of that (a Coordinate, if
sub is working properly) to wrapper(). Since
wrapper() expects a function, not a Coordinate,
that won't do anything useful.

What you probably meant to do is:

wrapper(sub)(one, two)

This passes the function sub to wrapper, which
returns another function; that function is then
called with arguments one and two.

-- 
Greg



More information about the Python-list mailing list