Re: Function __defaults__

2011-04-25 Thread Colin J. Williams
On 25-Apr-11 08:30 AM, Ken Seehart wrote: On 4/25/2011 4:59 AM, Colin J. Williams wrote: On 24-Apr-11 13:07 PM, Ken Seehart wrote: On 4/24/2011 2:58 AM, Steven D'Aprano wrote: Consider this in Python 3.1: def f(a=42): ... return a ... f() 42 f.__defaults__ = (23,) f() 23 Is this an a

Re: Function __defaults__

2011-04-25 Thread Ken Seehart
On 4/25/2011 4:59 AM, Colin J. Williams wrote: On 24-Apr-11 13:07 PM, Ken Seehart wrote: On 4/24/2011 2:58 AM, Steven D'Aprano wrote: Consider this in Python 3.1: def f(a=42): ... return a ... f() 42 f.__defaults__ = (23,) f() 23 Is this an accident of implementation, or can I trust t

Re: Function __defaults__

2011-04-25 Thread Colin J. Williams
On 24-Apr-11 13:07 PM, Ken Seehart wrote: On 4/24/2011 2:58 AM, Steven D'Aprano wrote: Consider this in Python 3.1: def f(a=42): ... return a ... f() 42 f.__defaults__ = (23,) f() 23 Is this an accident of implementation, or can I trust that changing function defaults in this fashion i

Re: Function __defaults__

2011-04-24 Thread Steven D'Aprano
On Sun, 24 Apr 2011 10:07:02 -0700, Ken Seehart wrote: > On 4/24/2011 2:58 AM, Steven D'Aprano wrote: [...] >> Is this an accident of implementation, or can I trust that changing >> function defaults in this fashion is guaranteed to work? > > This is documented in python 3, so I would expect it t

Re: Function __defaults__

2011-04-24 Thread Ken Seehart
Gotta love that email latency. :-D Ken On 4/24/2011 2:47 PM, Daniel Kluev wrote: On Mon, Apr 25, 2011 at 8:21 AM, Ken Seehart wrote: Good point, Benjamin. I didn't think of testing on Jython before answering. For practical purposes it's a really good idea to test obscure features against all

Re: Function __defaults__

2011-04-24 Thread Terry Reedy
On 4/24/2011 5:21 PM, Ken Seehart wrote: Good point, Benjamin. I didn't think of testing on Jython before answering. For practical purposes it's a really good idea to test obscure features against all potential target platforms. In this case, I would argue that**Benjamin's test demonstrates a bu

Re: Function __defaults__

2011-04-24 Thread Daniel Kluev
On Mon, Apr 25, 2011 at 8:21 AM, Ken Seehart wrote: > Good point, Benjamin.  I didn't think of testing on Jython before > answering.  For practical purposes it's a really good idea to test obscure > features against all potential target platforms. > > In this case, I would argue that Benjamin's te

Re: Function __defaults__

2011-04-24 Thread Ken Seehart
Oops, I must correct myself. Please ignore my previous post. As Daniel points out, Writable is specified in the Python 3 documentation. Apparently I was reading the documentation with only my right eye open, and the Writable tag fell on my blind spot. I concur that this unambiguously implies

Re: Function __defaults__

2011-04-24 Thread Ken Seehart
Good point, Benjamin. I didn't think of testing on Jython before answering. For practical purposes it's a really good idea to test obscure features against all potential target platforms. In this case, I would argue that**Benjamin's test demonstrates a bug in Jython. One could counter by p

Re: Function __defaults__

2011-04-24 Thread Ken Seehart
On 4/24/2011 2:58 AM, Steven D'Aprano wrote: Consider this in Python 3.1: def f(a=42): ... return a ... f() 42 f.__defaults__ = (23,) f() 23 Is this an accident of implementation, or can I trust that changing function defaults in this fashion is guaranteed to work? This is documen

Re: Function __defaults__

2011-04-24 Thread Daniel Kluev
http://docs.python.org/dev/reference/datamodel.html Callable types ... Special attributes: ... __defaults__A tuple containing default argument values for those arguments that have defaults, or None if no arguments have a default value Writable I don't see any 'implementation detail' mark the

Re: Function __defaults__

2011-04-24 Thread Benjamin Kaplan
On Sun, Apr 24, 2011 at 5:58 AM, Steven D'Aprano wrote: > Consider this in Python 3.1: > > def f(a=42): > ...     return a > ... f() > 42 f.__defaults__ = (23,) f() > 23 > > > Is this an accident of implementation, or can I trust that changing > function defaults in this fashio

Re: Function __defaults__

2011-04-24 Thread Terry Reedy
On 4/24/2011 5:58 AM, Steven D'Aprano wrote: Consider this in Python 3.1: def f(a=42): ... return a ... f() 42 f.__defaults__ = (23,) f() 23 Is this an accident of implementation, or can I trust that changing function defaults in this fashion is guaranteed to work? Interesting que

Function __defaults__

2011-04-24 Thread Steven D'Aprano
Consider this in Python 3.1: >>> def f(a=42): ... return a ... >>> f() 42 >>> f.__defaults__ = (23,) >>> f() 23 Is this an accident of implementation, or can I trust that changing function defaults in this fashion is guaranteed to work? -- Steven -- http://mail.python.org/mailman/lis