Re: [Python-ideas] An easier syntax for writing decorators (& similar things)?

Following up post from 10/8/07.
This is equivalent to: (1) decorator_withargs= partial( partial, prepartial ) , where prepartial is roughly the same as partial as you might expect: (2) 1 def prepartial(func, *args, **keywords): 2 def newfunc(*fargs, **fkeywords): 3 newkeywords = keywords.copy() 4 newkeywords.update(fkeywords) 5 return func(*(fargs+ args), **newkeywords) 6 newfunc.func = func 7 newfunc.args = args 8 newfunc.keywords = keywords 9 return newfunc Partial is the same outside of line 5: (3) 5 return func(*(args + fargs), **newkeywords) Results are the same: -> f 1 f -> 2 2 Intriguing.

I'm wondering, will Aaron ever realize that no-one understands his posts? On Jan 23, 2008 1:44 AM, Aaron Brady <castironpi@comcast.net> wrote:
-- --Guido van Rossum (home page: http://www.python.org/~guido/)

This is like totally. cool. Like Mr. Delobelle's post on the decorator's and stuff was like, a simplified version of this: decorator_withargs= partial( partial, prepartial ) Which is way cool, and I couldn't even understand, and like, wrap my brain around and stuff. Do uuuu understand? It?

On 23 Jan 2008, at 09:44, Aaron Brady wrote:
[where partial is as in functools and prepartial(f, x, y)(z, t) <=> f(z, t, x, y)] Indeed, and if one restricts decorator_withargs to keyword arguments, one can simply define it as: decorator_withargs = partial(partial, partial) Which is the curry operator! So decorator_withargs is some sort of curry. In fact I had never realised before that this was a way to define curry (for functions with 2 arguments) curry = partial(partial, partial) [if f is a two-arguments function then curry(f)(x)(y) is f(x, y)] This means that a meta-decorator (i.e. a decorator for decorators) is a kind of currying operator.
Intriguing.
! -- Arnaud

On Jan 23, 2008 7:06 PM, Aaron Brady <castironpi@comcast.net> wrote:
The Python Ideas list is really intended as sort of a testing ground for potential PEPs. What is it that you're proposing to add to or remove from the language? If you're just enjoying writing code in Python, comp.lang.python is a more appropriate place to post. STeVe -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy

On Jan 23, 2008 10:55 PM, Aaron Brady <castironpi@comcast.net> wrote:
So far, I've only seen this one use case for prepartial - and I'd rather have decorator_withargs itself than prepartial. Do you have any other use cases for prepartial (from real code somewhere)? Currently, I'm -1 on adding prepartial to functools, and +0.5 on adding something like decorator_withargs. STeVe -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy

On Jan 23, 2008 11:20 PM, Aaron Brady <castironpi@comcast.net> wrote:
Not that it matters, since it's already there, but no, I wasn't. In fact, the presence of partial is a big reason not to need prepartial -- most existing use cases are already covered by using partial. As Arnaud pointed out, if you restrict decorator_withargs to keyword arguments, you don't even need prepartial, you can just use partial itself. Thus, I don't see prepartial as really covering many new use cases. If you'd like to convince me otherwise, you're going to need to post some use cases from real code. STeVe -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy

Good. I was. It got in.
In fact, the presence of partial is a big reason not to need prepartial
Fallacy.
-- most existing use cases are already covered by using partial.
Lacks citation.
You don't.
Thus, I don't see prepartial as really covering many new use cases.
Syllogism: A -> B A _____ B Thus what again?
If you'd like to convince me otherwise, you're going to need to post some use cases from real code.
curry= partial( partial, prepartial ) [1] [1] http://www.smlnj.org/

Steven Bethard wrote: [after suggesting that prepartial doesn't gain us much over what we already have with functools.partial]
If you'd like to convince me otherwise, you're going to need to post some use cases from real code.
On Jan 24, 2008 1:36 PM, Aaron Brady <castironpi@comcast.net> wrote:
curry= partial( partial, prepartial ) [1]
I don't consider that a use case, or real code. ;-) Yes, you can construct curry with it. But what do you want to use curry for? Show me some actual Python packages that use the curry function (or your prepartial function) and then we can talk. STeVe -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy

Original function: 1. urlparse( urlstring[, default_scheme[, allow_fragments]]) 2. urlretrieve( url[, filename[, reporthook[, data]]]) Prepartial in action: 1. parseA= prepartial( 'ftp', False ) 2. retrieveA= prepartial( 'temp.htm', callbackA ) Equivalent: 1. parseAB= partial( default_scheme= 'ftp', allow_fragments= True ) 2. retrieveAB= partial( filename= 'temp.htm', reporthook= callbackA ) Equivalent calls: 1. parseA( 'www.cwi.nl/%7Eguido/Python.html' ) 2. retrieveA( 'http://python.org/' ) Motto: - Programmer time is important - The stdlib does not contain application-level design

Aaron, I don't know who you are, and I don't know what you are doing here, but this type of post with monosyllabic answers really pisses me off. I suggest you take it somewhere else, or learn to have a normal discussion. Where did you learn this type of behavior? If you think this is normal or even acceptable, well, it isn't. Also, you seem to be abusing this list for a purpose it isn't meant for. You risk being kicked off. On Jan 24, 2008 12:36 PM, Aaron Brady <castironpi@comcast.net> wrote:
-- --Guido van Rossum (home page: http://www.python.org/~guido/)

The personal dispute is tabled. Confer: http://mail.python.org/pipermail/python-ideas/2008-January/001357.html (Thu Jan 24 23:26:00 CET 2008).

I'm wondering, will Aaron ever realize that no-one understands his posts? On Jan 23, 2008 1:44 AM, Aaron Brady <castironpi@comcast.net> wrote:
-- --Guido van Rossum (home page: http://www.python.org/~guido/)

This is like totally. cool. Like Mr. Delobelle's post on the decorator's and stuff was like, a simplified version of this: decorator_withargs= partial( partial, prepartial ) Which is way cool, and I couldn't even understand, and like, wrap my brain around and stuff. Do uuuu understand? It?

On 23 Jan 2008, at 09:44, Aaron Brady wrote:
[where partial is as in functools and prepartial(f, x, y)(z, t) <=> f(z, t, x, y)] Indeed, and if one restricts decorator_withargs to keyword arguments, one can simply define it as: decorator_withargs = partial(partial, partial) Which is the curry operator! So decorator_withargs is some sort of curry. In fact I had never realised before that this was a way to define curry (for functions with 2 arguments) curry = partial(partial, partial) [if f is a two-arguments function then curry(f)(x)(y) is f(x, y)] This means that a meta-decorator (i.e. a decorator for decorators) is a kind of currying operator.
Intriguing.
! -- Arnaud

On Jan 23, 2008 7:06 PM, Aaron Brady <castironpi@comcast.net> wrote:
The Python Ideas list is really intended as sort of a testing ground for potential PEPs. What is it that you're proposing to add to or remove from the language? If you're just enjoying writing code in Python, comp.lang.python is a more appropriate place to post. STeVe -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy

On Jan 23, 2008 10:55 PM, Aaron Brady <castironpi@comcast.net> wrote:
So far, I've only seen this one use case for prepartial - and I'd rather have decorator_withargs itself than prepartial. Do you have any other use cases for prepartial (from real code somewhere)? Currently, I'm -1 on adding prepartial to functools, and +0.5 on adding something like decorator_withargs. STeVe -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy

On Jan 23, 2008 11:20 PM, Aaron Brady <castironpi@comcast.net> wrote:
Not that it matters, since it's already there, but no, I wasn't. In fact, the presence of partial is a big reason not to need prepartial -- most existing use cases are already covered by using partial. As Arnaud pointed out, if you restrict decorator_withargs to keyword arguments, you don't even need prepartial, you can just use partial itself. Thus, I don't see prepartial as really covering many new use cases. If you'd like to convince me otherwise, you're going to need to post some use cases from real code. STeVe -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy

Good. I was. It got in.
In fact, the presence of partial is a big reason not to need prepartial
Fallacy.
-- most existing use cases are already covered by using partial.
Lacks citation.
You don't.
Thus, I don't see prepartial as really covering many new use cases.
Syllogism: A -> B A _____ B Thus what again?
If you'd like to convince me otherwise, you're going to need to post some use cases from real code.
curry= partial( partial, prepartial ) [1] [1] http://www.smlnj.org/

Steven Bethard wrote: [after suggesting that prepartial doesn't gain us much over what we already have with functools.partial]
If you'd like to convince me otherwise, you're going to need to post some use cases from real code.
On Jan 24, 2008 1:36 PM, Aaron Brady <castironpi@comcast.net> wrote:
curry= partial( partial, prepartial ) [1]
I don't consider that a use case, or real code. ;-) Yes, you can construct curry with it. But what do you want to use curry for? Show me some actual Python packages that use the curry function (or your prepartial function) and then we can talk. STeVe -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy

Original function: 1. urlparse( urlstring[, default_scheme[, allow_fragments]]) 2. urlretrieve( url[, filename[, reporthook[, data]]]) Prepartial in action: 1. parseA= prepartial( 'ftp', False ) 2. retrieveA= prepartial( 'temp.htm', callbackA ) Equivalent: 1. parseAB= partial( default_scheme= 'ftp', allow_fragments= True ) 2. retrieveAB= partial( filename= 'temp.htm', reporthook= callbackA ) Equivalent calls: 1. parseA( 'www.cwi.nl/%7Eguido/Python.html' ) 2. retrieveA( 'http://python.org/' ) Motto: - Programmer time is important - The stdlib does not contain application-level design

Aaron, I don't know who you are, and I don't know what you are doing here, but this type of post with monosyllabic answers really pisses me off. I suggest you take it somewhere else, or learn to have a normal discussion. Where did you learn this type of behavior? If you think this is normal or even acceptable, well, it isn't. Also, you seem to be abusing this list for a purpose it isn't meant for. You risk being kicked off. On Jan 24, 2008 12:36 PM, Aaron Brady <castironpi@comcast.net> wrote:
-- --Guido van Rossum (home page: http://www.python.org/~guido/)

The personal dispute is tabled. Confer: http://mail.python.org/pipermail/python-ideas/2008-January/001357.html (Thu Jan 24 23:26:00 CET 2008).
participants (4)
-
Aaron Brady
-
Arnaud Delobelle
-
Guido van Rossum
-
Steven Bethard