From: SourceForge.net <no...@so...> - 2006-12-21 19:23:24
|
Bugs item #600790, was opened at 2002-08-27 13:39 Message generated for change (Comment added) made by leouserz You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112867&aid=600790&group_id=12867 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: Deferred Status: Open Resolution: None Priority: 4 Private: No Submitted By: Rich Landers (rt_landers) Assigned to: Nobody/Anonymous (nobody) Summary: Overriding automatically defined methods Initial Comment: When subclassing a java.util.List in Jython and I want to override __setitem__ to accept either a symbolic name or an integer index. However, when I define the __setitem__ method in my Jython subtype, I get a "TypeError: only integer keys accepted" exception. It seems that since __setitem__ was defined *automatically* for the List, my overriding method is never being called... -------- from java.lang import String from java.util import ArrayList class GoofyListMapThing (ArrayList): def __init__(self): self._elements = {} def __setitem__(self, key, element): print "GoofyListMapThing::__setitem__" # Handle string key or int key here... def __getitem__(self, key): print "GoofyListMapThing::__getitem__" # Handle string key or int key here... glmt = GoofyListMapThing() glmt["my-key"] = String("Element-1") # fails! ---------------------------------------------------------------------- Comment By: leouser (leouserz) Date: 2006-12-21 19:23 Message: Logged In: YES user_id=1277399 Originator: NO This problem is caused by PyInstance always checking if it has a CollectionProxy(non-collection subclasses appear not to be affected). If so it executes the CollectionProxies __setitem__(there are others, look for usage of getCollection() in PyInstance). A possible patch is to check the various dictionaries before checking for a collection proxy and executing the returned function if there is one. __findattr__ appears not to work, so the individual dictionaries may have to queried. leouser ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112867&aid=600790&group_id=12867 |