Re: 2.X functools.update_wrapper dislikes missing function attributes

2011-04-26 Thread samwyse
I just noticed an old issue that relate to this: http://bugs.python.org/issue3445 This dates back to 2008 and is marked as fixed, but my copies of Python 2.5.4 and 2.7.1 don't seem to implement it. I'll try to dig further. -- http://mail.python.org/mailman/listinfo/python-list

2.X functools.update_wrapper dislikes missing function attributes

2011-04-26 Thread samwyse
I noticed a behavior in Jython 2.5.2 that's arguably an implementation bug, but I'm wondering if it's something to be fixed for all versions of Python. I was wanting to decorate a Java instance method, and discovered that it didn't have a __module__ attribute. This caused the following message:

Re: Function attributes [OT]

2010-02-14 Thread Steve Holden
Terry Reedy wrote: > On 2/13/2010 8:14 AM, Steve Holden wrote: > >> Gmane is primarily a news (NNTP-based) service, though for reasons best >> know to the organizers they choose to rename the standard newsgroups to >> fit their own idea of how the universe should be organized, so there the >> grou

Re: Function attributes [OT]

2010-02-14 Thread Terry Reedy
On 2/13/2010 8:14 AM, Steve Holden wrote: Gmane is primarily a news (NNTP-based) service, though for reasons best know to the organizers they choose to rename the standard newsgroups to fit their own idea of how the universe should be organized, so there the group becomes gmane.comp.python.gener

Re: Function attributes [OT]

2010-02-13 Thread Mark Lawrence
Steve Holden wrote: Mark Lawrence wrote: Gabriel Genellina wrote: En Fri, 12 Feb 2010 04:29:12 -0300, Arnaud Delobelle escribió: I posted an example of a decorator that does just this in this thread a couple of days ago: http://mail.python.org/pipermail/python-list/2010-February/1235742.htm

Re: Function attributes [OT]

2010-02-13 Thread Steve Holden
Mark Lawrence wrote: > Gabriel Genellina wrote: >> En Fri, 12 Feb 2010 04:29:12 -0300, Arnaud Delobelle >> escribió: >> >>> I posted an example of a decorator that does just this in this thread a >>> couple of days ago: >>> >>> http://mail.python.org/pipermail/python-list/2010-February/1235742.htm

Re: Function attributes

2010-02-13 Thread Mark Lawrence
Gabriel Genellina wrote: En Fri, 12 Feb 2010 04:29:12 -0300, Arnaud Delobelle escribió: I posted an example of a decorator that does just this in this thread a couple of days ago: http://mail.python.org/pipermail/python-list/2010-February/1235742.html Ouch! I didn't see your post, nor seve

Re: Function attributes

2010-02-13 Thread Steve Howell
On Feb 10, 5:59 am, Muhammad Alkarouri wrote: > Hi everyone, > > What is the simplest way to access the attributes of a function from > inside it, other than using its explicit name? > In a function like f below: > > def f(*args): >     f.args = args >     print args > > is there any other way? >

Re: Function attributes

2010-02-12 Thread Gabriel Genellina
En Fri, 12 Feb 2010 04:29:12 -0300, Arnaud Delobelle escribió: I posted an example of a decorator that does just this in this thread a couple of days ago: http://mail.python.org/pipermail/python-list/2010-February/1235742.html Ouch! I didn't see your post, nor several other earlier posts i

Re: Function attributes

2010-02-11 Thread Arnaud Delobelle
"Gabriel Genellina" writes: > En Thu, 11 Feb 2010 00:25:00 -0300, Terry Reedy > escribió: >> On 2/10/2010 4:49 PM, Gabriel Genellina wrote: >> >>> I've written a decorator for "injecting" a __function__ name into the >>> function namespace, but I can't find it anywhere. I think I implemented >>>

Re: Function attributes

2010-02-11 Thread Terry Reedy
On 2/11/2010 6:36 PM, Gabriel Genellina wrote: This is simple to implement, but requires changing the function definition. My goal was to keep the original code unchanged, that is, leave it as: def f(n): if n > 0: return n*f(n-1) elif n==0: return 1 (like a normal, recursive function), and mak

Re: Function attributes

2010-02-11 Thread Gabriel Genellina
En Thu, 11 Feb 2010 00:25:00 -0300, Terry Reedy escribió: On 2/10/2010 4:49 PM, Gabriel Genellina wrote: I've written a decorator for "injecting" a __function__ name into the function namespace, but I can't find it anywhere. I think I implemented it by adding a fake additional argument and rep

Re: Function attributes

2010-02-10 Thread Terry Reedy
On 2/10/2010 4:49 PM, Gabriel Genellina wrote: I've written a decorator for "injecting" a __function__ name into the function namespace, but I can't find it anywhere. I think I implemented it by adding a fake additional argument and replacing LOAD_GLOBAL with LOAD_NAME in the bytecode. The dec

Re: Function attributes

2010-02-10 Thread Arnaud Delobelle
MRAB writes: > Does this mean that Python needs, say, __function__ (and perhaps also > __module__)? See PEP 3130 "Access to Current Module/Class/Function" (rejected) (http://www.python.org/dev/peps/pep-3130/) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Function attributes

2010-02-10 Thread Gabriel Genellina
En Wed, 10 Feb 2010 10:59:41 -0300, Muhammad Alkarouri escribió: What is the simplest way to access the attributes of a function from inside it, other than using its explicit name? In a function like f below: def f(*args): f.args = args print args is there any other way? See this:

Re: Function attributes

2010-02-10 Thread Arnaud Delobelle
Steven D'Aprano writes: > On Wed, 10 Feb 2010 18:31:23 +, Arnaud Delobelle wrote: > >> It's not ideal, but you can use a decorator like this to solve this >> problem: >> >> def bindfunction(f): >> def bound_f(*args, **kwargs): >> return f(bound_f, *args, **kwargs) >> bound_f.

Re: Function attributes

2010-02-10 Thread Steven D'Aprano
On Wed, 10 Feb 2010 18:31:23 +, Arnaud Delobelle wrote: > It's not ideal, but you can use a decorator like this to solve this > problem: > > def bindfunction(f): > def bound_f(*args, **kwargs): > return f(bound_f, *args, **kwargs) > bound_f.__name__ = f.__name__ > return b

Re: Function attributes

2010-02-10 Thread Steven D'Aprano
On Wed, 10 Feb 2010 17:23:36 +, MRAB wrote: > Stephen Hansen wrote: >> On Wed, Feb 10, 2010 at 6:36 AM, Steven D'Aprano >> > > wrote: >> >> On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote: >> > What is the simplest way to acce

Re: Function attributes

2010-02-10 Thread Arnaud Delobelle
Steven D'Aprano writes: > On Wed, 10 Feb 2010 10:08:47 -0500, John Posner wrote: > >>> This won't work correctly, because old_f still tries to refer to itself >>> under the name "f", and things break very quickly. >> >> They didn't break immediately for me -- what am I missing?: > > The original

Re: Function attributes

2010-02-10 Thread John Posner
On 2/10/2010 10:24 AM, Bruno Desthuilliers wrote: They didn't break immediately for me -- what am I missing?: The fact that in the OP's snippet, code inside f's body refers to f by its name. Of course! Tx. -John -- http://mail.python.org/mailman/listinfo/python-list

Re: Function attributes

2010-02-10 Thread MRAB
Stephen Hansen wrote: On Wed, Feb 10, 2010 at 6:36 AM, Steven D'Aprano > wrote: On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote: > What is the simplest way to access the attributes of a function from > inside it, other than

Re: Function attributes

2010-02-10 Thread Stephen Hansen
On Wed, Feb 10, 2010 at 6:36 AM, Steven D'Aprano < st...@remove-this-cybersource.com.au> wrote: > On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote: > > What is the simplest way to access the attributes of a function from > > inside it, other than using its explicit name? In a function

Re: Function attributes

2010-02-10 Thread Steven D'Aprano
On Wed, 10 Feb 2010 10:08:47 -0500, John Posner wrote: >> This won't work correctly, because old_f still tries to refer to itself >> under the name "f", and things break very quickly. > > They didn't break immediately for me -- what am I missing?: The original function f doesn't try to refer to

Re: Function attributes

2010-02-10 Thread Bruno Desthuilliers
John Posner a écrit : On 2/10/2010 9:36 AM, Steven D'Aprano wrote: On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote: (snip) def f(*args): f.args = args print args (snip) I completely agree with you. It is a wart that functions are only able to refer to themselves by

Re: Function attributes

2010-02-10 Thread John Posner
On 2/10/2010 9:36 AM, Steven D'Aprano wrote: On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote: Hi everyone, What is the simplest way to access the attributes of a function from inside it, other than using its explicit name? In a function like f below: def f(*args): f.args = a

Re: Function attributes

2010-02-10 Thread Krister Svanlund
On Wed, Feb 10, 2010 at 2:59 PM, Muhammad Alkarouri wrote: > Hi everyone, > > What is the simplest way to access the attributes of a function from > inside it, other than using its explicit name? > In a function like f below: > > def f(*args): >    f.args = args >    print args > > is there any ot

Re: Function attributes

2010-02-10 Thread Steven D'Aprano
On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote: > Hi everyone, > > What is the simplest way to access the attributes of a function from > inside it, other than using its explicit name? In a function like f > below: > > def f(*args): > f.args = args > print args > > is ther

Function attributes

2010-02-10 Thread Muhammad Alkarouri
Hi everyone, What is the simplest way to access the attributes of a function from inside it, other than using its explicit name? In a function like f below: def f(*args): f.args = args print args is there any other way? I am guessing the next question will be: should I really care? It ju

Re: style query: function attributes for return codes?

2004-12-10 Thread holger krekel
[Reinhold Birkenfeld Fri, Dec 10, 2004 at 08:42:10PM +0100] > holger krekel wrote: > > class Connection(object): > > def __init__(self, **kw): > > for name in kw: > > assert name in ('good', 'badauth', 'noserver'), name > > setattr(self, n

Re: style query: function attributes for return codes?

2004-12-10 Thread Reinhold Birkenfeld
gt; >> This is obviously just evil, since a misspelling in the string >> return is treacherous. > > Right. > > I usually like to look at such problems from the angle of > what is most convenient for the *caller* side? > > And having to adress function attribu

Re: style query: function attributes for return codes?

2004-12-10 Thread george young
On Fri, 10 Dec 2004 16:40:25 GMT Steven Bethard <[EMAIL PROTECTED]> threw this fish to the penguins: > george young wrote: > > This is obviously just evil, since a misspelling in the string > > return is treacherous. I'm considering function attributes: > > >

Re: style query: function attributes for return codes?

2004-12-10 Thread Steven Bethard
Robert Kern wrote: Steven Bethard wrote: Sorry, I also meant to add that the other obvious way of dealing with this kind of thing is to make the results keyword parameters: def get_connection(GOOD=1, BAD_AUTH=2, NO_SERVER=3): if tcp_conn(): if server_allows_conn(): return

Re: style query: function attributes for return codes?

2004-12-10 Thread holger krekel
ight. I usually like to look at such problems from the angle of what is most convenient for the *caller* side? And having to adress function attributes does not seem convenient. I'd probably like to do from the caller side something like: conn = get_connection() if conn.good:

Re: style query: function attributes for return codes?

2004-12-10 Thread Robert Kern
Steven Bethard wrote: Sorry, I also meant to add that the other obvious way of dealing with this kind of thing is to make the results keyword parameters: def get_connection(GOOD=1, BAD_AUTH=2, NO_SERVER=3): if tcp_conn(): if server_allows_conn(): return GOOD else:

Re: style query: function attributes for return codes?

2004-12-10 Thread Steven Bethard
eturn 'no_server' cn = get_connection() if cn == 'good_con': ... This is obviously just evil, since a misspelling in the string return is treacherous. I'm considering function attributes: def get_connection(): if tcp_conn(): if server_allows_conn(): return get_con

Re: style query: function attributes for return codes?

2004-12-10 Thread Steven Bethard
george young wrote: This is obviously just evil, since a misspelling in the string return is treacherous. I'm considering function attributes: def get_connection(): if tcp_conn(): if server_allows_conn(): return get_connection.GOOD else: r

style query: function attributes for return codes?

2004-12-10 Thread george young
cn = get_connection() if cn == 'good_con': ... This is obviously just evil, since a misspelling in the string return is treacherous. I'm considering function attributes: def get_connection(): if tcp_conn(): if server_allows_conn(): return get_con