Message6477

Author smeatonj
Recipients smeatonj
Date 2011-04-11.03:36:23
SpamBayes Score 5.695444e-14
Marked as misclassified No
Message-id <1302492984.58.0.3120387547.issue1730@psf.upfronthosting.co.za>
In-reply-to
Content
Actual Jython version is: 2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06)

Example (Jython):

(InteractiveConsole)
>>> from functools import partial
>>> def my_func(arg1):     
...     """my_func doc string"""
...     return "arg: %s" %arg1
... 
>>> my_func("hi")
'arg: hi'
>>> my_func.__doc__
'my_func doc string'
>>> partial
<type '_functools.partial'>
>>> partial_func = partial(my_func, 'hi')
>>> partial_func()
'arg: hi'
>>> partial_func.__doc__
>>> partial_func.__doc__ = my_func.__doc__
Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: readonly attribute
>>> 

Same thing in Python 2.7:

Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34) 
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from functools import partial
>>> def my_func(arg1):
...     """my_func doc string"""
...     return "arg: %s" % arg1
... 
>>> my_func("hi")
'arg: hi'
>>> my_func.__doc__
'my_func doc string'
>>> partial_func = partial(my_func, "hi")
>>> partial_func()
'arg: hi'
>>> partial_func.__doc__
'partial(func, *args, **keywords) - new function with partial application\n    of the given arguments and keywords.\n'
>>> partial_func.__doc__ = my_func.__doc__
>>> 

This was discovered using Django 1.3. For those familiar with Django, any template tags registered as a @register.simple_tag will encounter this issue. On further investigation, it will also break any include tags, which are common to the majority of django sites.

The documentation for Jython functools, http://www.jython.org/docs/library/functools.html#partial-objects , says that only the .func, .args, and .keywords are readonly.

The Python documentation for partial even has an example showing the modification of the __doc__ string.
History
Date User Action Args
2011-04-11 03:36:24smeatonjsetmessageid: <1302492984.58.0.3120387547.issue1730@psf.upfronthosting.co.za>
2011-04-11 03:36:24smeatonjsetrecipients: + smeatonj
2011-04-11 03:36:24smeatonjlinkissue1730 messages
2011-04-11 03:36:23smeatonjcreate