FAQ
I noticed a behavior in Jython 2.5.2 that's arguably an implementation
bug, but I'm wondering if it's something to be fixed for all versions
of Python. I was wanting to decorate a Java instance method, and
discovered that it didn't have a __module__ attribute. This caused
the following message:

File "C:\jython2.5.2\Lib\functools.py", line 33, in update_wrapper
setattr(wrapper, attr, getattr(wrapped, attr))
AttributeError: 'instancemethod' object has no attribute '__module__'

The relevant code is:
for attr in assigned:
setattr(wrapper, attr, getattr(wrapped, attr))
for attr in updated:
getattr(wrapper, attr).update(getattr(wrapped, attr, {}))

Note that attributes to be updated get a default value. I'm proposing
that attributes to be assigned do the same, most likely an empty
string. A non-string value (such as None) could break anything
expecting a string value, so it seems like a bad idea. Python 3.2
catches AttributeError and passes. I don't like this solution. While
it prevents any attributes from being added to the wrapper, the
wrapper likely has its own values (at least for the default
attributes) and using those values could cause confusion.

Any opinions?

Search Discussions

  • Sam Denton at Apr 26, 2011 at 9:22 pm
    I just noticed an old issue that relate to this: http://bugs.python.org/issue3445

    This dates back to 2008 and is marked as fixed, but my copies of
    Python 2.5.4 and 2.7.1 don't seem to implement it. I'll try to dig
    further.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedApr 26, '11 at 9:12p
activeApr 26, '11 at 9:22p
posts2
users1
websitepython.org

1 user in discussion

Sam Denton: 2 posts

People

Translate

site design / logo © 2023 Grokbase