Message6477
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. |
|
Date |
User |
Action |
Args |
2011-04-11 03:36:24 | smeatonj | set | messageid: <1302492984.58.0.3120387547.issue1730@psf.upfronthosting.co.za> |
2011-04-11 03:36:24 | smeatonj | set | recipients:
+ smeatonj |
2011-04-11 03:36:24 | smeatonj | link | issue1730 messages |
2011-04-11 03:36:23 | smeatonj | create | |
|