<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
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.<br>
<br>
In this case, I would argue that<b> </b>Benjamin's test
demonstrates a bug in Jython.<br>
<br>
One could counter by pointing out that the documentation does not
specify that the __defaults__ attribute is writable. However, in
that case, Jython should explicitly make that attribute read only
(as well as any other magic attributes where modification is
silently ignored). That way, at least it would raise an exception
in Jython.<br>
<br>
Therefore, I would also suggest that the behavior of writable magic
attributes should be added to the documentation and the python test
suite. <br>
<br>
On the other hand, if for some reason it is decided that support for
such functionality is not desired in Python, then write access to
such attributes should be deprecated and later removed. However, I
happen to like the ability to do this kind of thing, so I would vote
for specifying the current CPython 3 behavior (as demonstrated in
Steven's initial post) in the Python documentation.<br>
<br>
On 4/24/2011 10:02 AM, Benjamin Kaplan wrote:
<blockquote
cite="mid:BANLkTi=hLzcxEGMtsZiSVGdN4bi4A4DCLw@mail.gmail.com"
type="cite">
<pre wrap="">On Sun, Apr 24, 2011 at 5:58 AM, Steven D'Aprano
<a class="moz-txt-link-rfc2396E" href="mailto:steve+comp.lang.python@pearwood.info"><steve+comp.lang.python@pearwood.info></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Consider this in Python 3.1:
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">def f(a=42):
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap="">... return a
...
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">f()
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap="">42
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">f.__defaults__ = (23,)
f()
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap="">23
Is this an accident of implementation, or can I trust that changing
function defaults in this fashion is guaranteed to work?
--
Steven
</pre>
</blockquote>
<pre wrap="">
Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54)
[Java HotSpot(TM) 64-Bit Server VM (Apple Inc.)] on java1.6.0_24
Type "help", "copyright", "credits" or "license" for more information.
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">def f(a=42) :
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap="">... return a
...
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">f()
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap="">42
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">f.__defaults__ = (23,)
f()
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap="">42
I'm going to go with implementation detail.
</pre>
<blockquote type="cite">
<pre wrap="">
--
<a class="moz-txt-link-freetext" href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list</a>
</pre>
</blockquote>
</blockquote>
<br>
</body>
</html>