scoping weirdness
Alex Martelli
aleax at aleax.it
Mon Aug 27 09:52:05 EDT 2001
"Marcin 'Qrczak' Kowalczyk" <qrczak at knm.org.pl> wrote in message
news:slrn.pl.9ok9t3.bm8.qrczak at qrnik.zagroda...
> Mon, 27 Aug 2001 12:06:21 +0200, Alex Martelli <aleax at aleax.it> pisze:
>
> > def curry_to_argumentlessness(*args, **kwds):
> > def totally_curried_function():
> > return args[0](*args[1:],**kwds)
> > return totally_curried_function
>
> A little bit nicer:
>
> def curry_to_argumentlessness(fun, *args, **kwds):
> def totally_curried_function():
> return fun(*args, **kwds)
> return totally_curried_function
Except, of course, that this breaks down badly in
one special case...: when one among the keywords
in kwds is 'fun'. To wit:
def press_button(fun):
print "text is",fun
use = curry_to_argumentlessness(press_button, fun="happy")
...oops...?!
We don't want to have to document peculiar, strange
restrictions due to internals when we develop general
purpose tools like curry_to_argumentlessness such
as "it works to curry any callable with its arguments
EXCEPT when one of the arguments is a keyword-argument
whose argument name is 'fun' in which case we're out
of luck because we wanted to use a version of our
implementation which some thought was 'a little
bit nicer', sorry folks".
I consider it *MUCH* nicer to use my original version
and avoid any such restriction. And no, there is
no restriction in my version about having keyword
arguments named 'args' or 'kwds', either -- check.
Alex
More information about the Python-list
mailing list