Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add decorator for make functions partial applicable #59888

Closed
ArvinMoezzi mannequin opened this issue Aug 16, 2012 · 5 comments
Closed

add decorator for make functions partial applicable #59888

ArvinMoezzi mannequin opened this issue Aug 16, 2012 · 5 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@ArvinMoezzi
Copy link
Mannequin

ArvinMoezzi mannequin commented Aug 16, 2012

BPO 15683
Nosy @bitdancer

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2012-08-16.15:23:09.028>
created_at = <Date 2012-08-16.08:34:39.939>
labels = ['type-feature', 'library']
title = 'add decorator for make functions partial applicable'
updated_at = <Date 2012-08-16.15:43:47.593>
user = 'https://bugs.python.org/ArvinMoezzi'

bugs.python.org fields:

activity = <Date 2012-08-16.15:43:47.593>
actor = 'r.david.murray'
assignee = 'none'
closed = True
closed_date = <Date 2012-08-16.15:23:09.028>
closer = 'r.david.murray'
components = ['Library (Lib)']
creation = <Date 2012-08-16.08:34:39.939>
creator = 'Arvin.Moezzi'
dependencies = []
files = []
hgrepos = []
issue_num = 15683
keywords = []
message_count = 5.0
messages = ['168356', '168358', '168382', '168385', '168386']
nosy_count = 2.0
nosy_names = ['r.david.murray', 'Arvin.Moezzi']
pr_nums = []
priority = 'normal'
resolution = None
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue15683'
versions = ['Python 2.6']

@ArvinMoezzi
Copy link
Mannequin Author

ArvinMoezzi mannequin commented Aug 16, 2012

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?

@ArvinMoezzi ArvinMoezzi mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Aug 16, 2012
@ArvinMoezzi
Copy link
Mannequin Author

ArvinMoezzi mannequin commented Aug 16, 2012

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

@bitdancer
Copy link
Member

YAGNI, is what I think. Or if you do need it, put it in your application. (To tell you the truth, it just looks confusing to me...it strikes me as too magical.)

Regardless, this is more of a python-ideas kind of issue, so I suggest raising it there if you want to pursue it.

@ArvinMoezzi
Copy link
Mannequin Author

ArvinMoezzi mannequin commented Aug 16, 2012

Thanks for your feedback.

@bitdancer
Copy link
Member

Thanks for your suggestion, even though I'm rejecting the suggestion as a bug tracker issue. (I should have said that at the start of my answer.)

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant