Modifying func closure

Michele Simionato michele.simionato at gmail.com
Sun Jul 11 00:28:25 EDT 2004


"Robert Brewer" <fumanchu at amor.org> wrote in message news:<mailman.214.1089484067.5135.python-list at python.org>...
> 
> Off-list, Jacek gave some reasons for preferring closures over classes.
> Jacek, can I post them so we can discuss them further? Perhaps we could
> revisit mutable closures.
> 

I am sure Jacek's reasons are pretty good ones. He already wrote a lot
in
previous threads on c.l.p. One of the things that disturb me is that
faking functions with callable objects sucks. You need to write
something like

class function(object):
    def __init__(self,func):
        self.__func__=func
    def __call__(self,*args,**kw):
        return self.__func__(*args,**kw)
    def __get__(self,obj,cls=None):
        return self.__func__.__get__(obj,cls)

to have the callable objects respect the descriptor protocol as if
they were functions. This is too verbose for my taste. So I prefer
to return real function by using a closure instead of a class (but
then read-write closures becomes important). Alternatively, I would
need a
way to subclass from FunctionType. More or this thread:

http://groups.google.it/groups?hl=it&lr=&ie=UTF-8&selm=95aa1afa.0402262158.5b33de79%40posting.google.com&rnum=1


    Michele Simionato



More information about the Python-list mailing list