Function __defaults__

Terry Reedy tjreedy at
Sun Apr 24 23:53:59 CEST 2011

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 bug in
> Jython.

Benjamin's 'test' only tested that he could add a new attribute to a 
function object, as he did not use the proper 2.x name, func_defaults.

> One could counter by pointing out that the documentation does not
> specify that the __defaults__ attribute is writable.

The 3.x docs, as another pointed out, does so specify. The same was true 
in 2.x at least by 2.5
"func_defaults 	A tuple containing default argument values for those 
arguments that have defaults, or None if no arguments have a default 
value 	Writable"

So if the following does not work in Jython 2.5

def f(a=42) :
    return a
# 42
f.func_defaults = (23,)
# 23

then it *does* have a bug with respect to matching the Python 2.5 spec.

Terry Jan Reedy

More information about the Python-list mailing list