From: Leo U. <leo...@ya...> - 2007-01-15 00:40:54
|
Well one way may be to be explicit about what is can be set, this appears to work ok: import org.python.core.*; public class PyThing extends PyObject{ static PyType type = PyType.fromClass(PyThing.class); public static void typeSetup(PyObject dict, PyType.Newstyle marker){ dict.__setitem__("thing", new PyFieldDescr("thing", PyThing.class, "thing")); dict.__setitem__("__new__",new PyNewWrapper(PyObject.class,"__new__",-1,-1) { public PyObject new_impl(boolean init,PyType subtype,PyObject[]args,String[]keywords) { return new PyThing(); } }); } public int thing = 1; public PyThing(){ super(type); } } leouser --- Paul Drummond <pau...@ds...> wrote: > Leo User wrote: > > interesting, > > > > import org.python.core.*; > > > > public class PyThing extends PyObject{ > > > > static PyType type = > > PyType.fromClass(PyThing.class); > > > > public int thing = 1; > > > > public PyThing(){ > > super(type); > > } > > > > } > > > > this gives me a PyThing to create in the jython > > interpreter. I can access "thing" like you say > but I > > cannot set it. PyReflectedField is bombing > because > > __set__ is not overriden and the implementation in > > PyObject throws an exception. > > Yeah, this is the problem I have. I figured I must > be doing it wrong when I got the exception. > > Any idea why PyReflectedField doesn't implement > __set__()? > > What's the point in auto-exposing a field if you > can't set it? > > > With that said, it is kind of wicked that "thing" > is autoexposed > > like it is. Maybe an annotative approach would be > better in the > > future to deal with this > > > > @Expose > > public int thing > > Yeah, being explicit (with annotations or an > alternative method) would be good. Currently, I am > struggling trying to understand what Jython does and > doesn't do in terms of reflection. There are > lots of implicit rules to folow like "if a field is > public it is auto-exposed" and "if a method has > "PyObject[] args, String[] kw" as arguments then it > will support keywords", etc, etc. The only way > to figure these things out is to step through the > code which is why I am making such slow progress! > > But anyway, back to the immediate problem. Given > that PyReflectedField doesn't allowing setting an > attribute, how should I progress? I am trying to > learn from looking at the code in other modules > but I get bogged down and confused quite quickly ;) > > > I could just have my own "dict" and manipulate it > via the ___xxxattr__() methods but I don't want to > do that if it's reinventing the wheel or too crude > or whatever! Any ideas? > > Cheers, > Paul. > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get > the chance to share your > opinions on IT & business topics through brief > surveys - and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Jython-dev mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-dev > ____________________________________________________________________________________ Be a PS3 game guru. Get your game face on with the latest PS3 news and previews at Yahoo! Games. http://videogames.yahoo.com/platform?platform=120121 |