[issue15683] add decorator for make functions partial applicable

2012-08-16 Thread Arvin Moezzi

New submission from Arvin Moezzi:

I am not sure if this is the right way to do it but IMHO it would be great to
have a function decorator/transformer to make functions partial applicable
using functools.partial. Like


from functools import partial

class partial_applicable():
def __call__(self, func):
def __wrapper(*args, **kvargs):
try:
return func(*args, **kvargs)
except TypeError:
return partial(func, *args, **kvargs)

return __wrapper

Then you could do like:

@partial_applicable()
def substract(left, right):
return left - right

substract(10, 100) 
 = -90

rclose = substract(right = 1000)
 = rclose(10) = -990

lclose = substract(1)
 = lclose(10) = -9

What do you think?

--
components: Library (Lib)
messages: 168356
nosy: Arvin.Moezzi
priority: normal
severity: normal
status: open
title: add decorator for make functions partial applicable
type: enhancement
versions: Python 2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15683
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15683] add decorator for make functions partial applicable

2012-08-16 Thread Arvin Moezzi

Arvin Moezzi added the comment:

Or maybe even

class partial_applicable():
def __call__(self, func):
def __wrapper(*args, **kvargs):
try:
return func(*args, **kvargs)
except TypeError:
partial_func = partial(func, *args, **kvargs)
return partial_applicable()(partial_func)

return __wrapper

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15683
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15683] add decorator for make functions partial applicable

2012-08-16 Thread Arvin Moezzi

Arvin Moezzi added the comment:

Thanks for your feedback.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15683
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com