Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #3963

Re: Function __defaults__

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Function __defaults__
Date 2011-04-24 17:53 -0400
References <4db3f444$0$29978$c3e8da3$5496439d@news.astraweb.com> <BANLkTi=hLzcxEGMtsZiSVGdN4bi4A4DCLw@mail.gmail.com> <4DB49473.4000204@seehart.com>
Newsgroups comp.lang.python
Message-ID <mailman.804.1303682052.9059.python-list@python.org> (permalink)

Show all headers | View raw


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

http://docs.python.org/release/2.5.4/ref/types.html
"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
f()
# 42
f.func_defaults = (23,)
f()
# 23

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

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Function __defaults__ Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-24 09:58 +0000
  Re: Function __defaults__ Terry Reedy <tjreedy@udel.edu> - 2011-04-24 12:48 -0400
  Re: Function __defaults__ Benjamin Kaplan <benjamin.kaplan@case.edu> - 2011-04-24 13:02 -0400
  Re: Function __defaults__ Daniel Kluev <dan.kluev@gmail.com> - 2011-04-25 04:18 +1100
  Re: Function __defaults__ Ken Seehart <ken@seehart.com> - 2011-04-24 10:07 -0700
    Re: Function __defaults__ Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-25 02:00 +0000
  Re: Function __defaults__ Ken Seehart <ken@seehart.com> - 2011-04-24 14:44 -0700
  Re: Function __defaults__ Daniel Kluev <dan.kluev@gmail.com> - 2011-04-25 08:47 +1100
  Re: Function __defaults__ Terry Reedy <tjreedy@udel.edu> - 2011-04-24 17:53 -0400
  Re: Function __defaults__ Ken Seehart <ken@seehart.com> - 2011-04-24 14:54 -0700
  Re: Function __defaults__ "Colin J. Williams" <cjw@ncf.ca> - 2011-04-25 07:59 -0400
  Re: Function __defaults__ Ken Seehart <ken@seehart.com> - 2011-04-25 05:30 -0700
  Re: Function __defaults__ "Colin J. Williams" <cjw@ncf.ca> - 2011-04-25 10:24 -0400

csiph-web