|
From: Barbalute <Bar...@gm...> - 2010-03-08 19:49:37
|
As the name suggests, it seems that copy and deepcopy aren't copying the variables in my Java class. I currently have a Python class extending an existing Java abstract class. For various reasons, I've overwritten clone() in the Python class so that when the Java class calls it, it returns a deepcopy() of itself. This seems to properly copy the methods from the class, but the variables from the abstract Java class are lost in the copy, and I have no idea why. In the overwritten Python clone() method, I'm able to manually copy over the variables, doing for example: x = copy.deepcopy(self) x.name = self.name return x But this shouldn't be necessary and becomes increasingly unwieldy for classes with lots of variables. If I don't do it, though, name is not set in x and will return null in Java. Am I doing something wrong, or is something broken with copy() and deepcopy()? Thanks for your time. -- View this message in context: http://old.nabble.com/copy-and-deepcopy-not-copying-Java-class-variables--tp27826254p27826254.html Sent from the jython-users mailing list archive at Nabble.com. |
|
From: Andy R. <bar...@gm...> - 2010-03-08 22:28:33
|
Thanks very much to both of you for the help, but with the new copy.py I'm
getting an error:
raise Error('un-deep-copyable object of type %s' % type(x))
copy.Error: un-deep-copyable object of type <class 'testClass.testClass'>
testClass in this case is a very simple class containing only a single
integer. Any ideas why this might be happening? I can give my code if it
will help.
Thanks again,
Barbalute
On Mon, Mar 8, 2010 at 4:08 PM, Josh Juneau <jun...@gm...> wrote:
> Yes, there is an issue with the current version of copy.py that is being
> distributed with 2.5.1. You can read more about the issue on the bug
> tracker at http://bugs.jython.org/issue1551...but it specifically
> addresses issues while making copies of Java objects using copy() and
> deepcopy(). I am going to be checking in the attached version of copy.py
> which has been corrected to address the issues related to the bug report.
> There is also an effort taking place to convert the current version of
> copy.py into a Java implementation to help boost performance a bit. Please
> stay tuned for that version sometime in the future.
>
> If you have a moment, please drop the attached version of copy.py into your
> jython Lib directory and give it a try. Hopefully it will resolve your
> issues. If it does not, please submit another bug or add onto issue 1551.
>
> Thanks
>
>
> Josh Juneau
> jun...@gm...
> http://jj-blogger.blogspot.com
> http://www.jythonpodcast.com
> Twitter ID: javajuneau
>
>
>
> On Mon, Mar 8, 2010 at 1:49 PM, Barbalute <Bar...@gm...> wrote:
>
>>
>> As the name suggests, it seems that copy and deepcopy aren't copying the
>> variables in my Java class.
>>
>> I currently have a Python class extending an existing Java abstract class.
>> For various reasons, I've overwritten clone() in the Python class so that
>> when the Java class calls it, it returns a deepcopy() of itself.
>>
>> This seems to properly copy the methods from the class, but the variables
>> from the abstract Java class are lost in the copy, and I have no idea why.
>>
>> In the overwritten Python clone() method, I'm able to manually copy over
>> the
>> variables, doing for example:
>>
>> x = copy.deepcopy(self)
>> x.name = self.name
>> return x
>>
>> But this shouldn't be necessary and becomes increasingly unwieldy for
>> classes with lots of variables. If I don't do it, though, name is not set
>> in
>> x and will return null in Java. Am I doing something wrong, or is
>> something
>> broken with copy() and deepcopy()?
>>
>> Thanks for your time.
>> --
>> View this message in context:
>> http://old.nabble.com/copy-and-deepcopy-not-copying-Java-class-variables--tp27826254p27826254.html
>> Sent from the jython-users mailing list archive at Nabble.com.
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Download Intel® Parallel Studio Eval
>> Try the new software tools for yourself. Speed compiling, find bugs
>> proactively, and fine-tune applications for parallel performance.
>> See why Intel Parallel Studio got high marks during beta.
>> http://p.sf.net/sfu/intel-sw-dev
>> _______________________________________________
>> Jython-users mailing list
>> Jyt...@li...
>> https://lists.sourceforge.net/lists/listinfo/jython-users
>>
>
>
|
|
From: Andy R. <bar...@gm...> - 2010-03-13 08:06:26
|
Sorry for the late reply! It's been a busy week. I'm still getting an error. I have a (serializable) Java class and a Python class that extends it, and I've loaded the Python class (successfully) into Java. After instantiating the Python class in Java, I'd like to make a copy of it from Java. So I've tried - with the new files you've sent me - creating a new function in the superclass (that returned null) but I overrode it in the Python class, having it return a copy.deepcopy(pythonClassName). That didn't work, so what I then tried was using the copy method from DeepJavaCopier, and it's giving me a ClassNotFound error when it tries to read the object back in (obj = in.readObject();) This is the first line of the error I'm getting: java.lang.ClassNotFoundException: org.python.proxies.MyTestClass$MyTestClass$0 So I'm not sure if I'm using it properly - my class is only serializable (not cloneable), because I only want to make a deep copy of it. Thanks again for all your help, Andy On Tue, Mar 9, 2010 at 2:54 AM, Josh Juneau <jun...@gm...> wrote: > Andy- > > You are correct in that there were still issues with the version of copy.py > which I previously sent to you. I think that the issues you were seeing are > twofold. There are a couple of rules one must follow in order to create > copies of Java objects. First, in order to be deep copyable, a Java object > must implement java.io.Serializable. Ensure that your testClass is > serializable. Second, if you are trying to create a shallow copy of the > object then it must implement the java.lang.Cloneable interface and override > the clone() method. I've attached one such Java object (Person.java) that > should be both shallow and deep copyable via the new copy.py (which is also > included). > > I found that in the previous version I sent to you , Java classes were not > being deep copied correctly as the Python code was unable to actually create > the copy. In order to make it work, I've re-written the deep copy > implementation in Java code and now the copy.py uses the new Java > implementation each time a deep copy is necessary. This seems to do the > trick as I believe the Python deep copy implementation was encountering > issues in translation and creating a proxy object rather than a straight > copy. > > To use this new version, please place DeepJavaCopier.class, and copy.py in > your Lib directory. Then, ensure that your Java object adheres to the rules > mentioned above. The solution definitely could use some further testing, so > any help would be appreciated! > > Thanks > > > Josh Juneau > jun...@gm... > http://jj-blogger.blogspot.com > http://www.jythonpodcast.com > Twitter ID: javajuneau > > > On Mon, Mar 8, 2010 at 4:28 PM, Andy Rose <bar...@gm...> wrote: > >> Thanks very much to both of you for the help, but with the new copy.py I'm >> getting an error: >> >> raise Error('un-deep-copyable object of type %s' % type(x)) >> copy.Error: un-deep-copyable object of type <class 'testClass.testClass'> >> >> testClass in this case is a very simple class containing only a single >> integer. Any ideas why this might be happening? I can give my code if it >> will help. >> >> Thanks again, >> Barbalute >> >> >> On Mon, Mar 8, 2010 at 4:08 PM, Josh Juneau <jun...@gm...> wrote: >> >>> Yes, there is an issue with the current version of copy.py that is being >>> distributed with 2.5.1. You can read more about the issue on the bug >>> tracker at http://bugs.jython.org/issue1551...but it specifically >>> addresses issues while making copies of Java objects using copy() and >>> deepcopy(). I am going to be checking in the attached version of copy.py >>> which has been corrected to address the issues related to the bug report. >>> There is also an effort taking place to convert the current version of >>> copy.py into a Java implementation to help boost performance a bit. Please >>> stay tuned for that version sometime in the future. >>> >>> If you have a moment, please drop the attached version of copy.py into >>> your jython Lib directory and give it a try. Hopefully it will resolve your >>> issues. If it does not, please submit another bug or add onto issue 1551. >>> >>> Thanks >>> >>> >>> Josh Juneau >>> jun...@gm... >>> http://jj-blogger.blogspot.com >>> http://www.jythonpodcast.com >>> Twitter ID: javajuneau >>> >>> >>> >>> On Mon, Mar 8, 2010 at 1:49 PM, Barbalute <Bar...@gm...> wrote: >>> >>>> >>>> As the name suggests, it seems that copy and deepcopy aren't copying the >>>> variables in my Java class. >>>> >>>> I currently have a Python class extending an existing Java abstract >>>> class. >>>> For various reasons, I've overwritten clone() in the Python class so >>>> that >>>> when the Java class calls it, it returns a deepcopy() of itself. >>>> >>>> This seems to properly copy the methods from the class, but the >>>> variables >>>> from the abstract Java class are lost in the copy, and I have no idea >>>> why. >>>> >>>> In the overwritten Python clone() method, I'm able to manually copy over >>>> the >>>> variables, doing for example: >>>> >>>> x = copy.deepcopy(self) >>>> x.name = self.name >>>> return x >>>> >>>> But this shouldn't be necessary and becomes increasingly unwieldy for >>>> classes with lots of variables. If I don't do it, though, name is not >>>> set in >>>> x and will return null in Java. Am I doing something wrong, or is >>>> something >>>> broken with copy() and deepcopy()? >>>> >>>> Thanks for your time. >>>> -- >>>> View this message in context: >>>> http://old.nabble.com/copy-and-deepcopy-not-copying-Java-class-variables--tp27826254p27826254.html >>>> Sent from the jython-users mailing list archive at Nabble.com. >>>> >>>> >>>> >>>> ------------------------------------------------------------------------------ >>>> Download Intel® Parallel Studio Eval >>>> Try the new software tools for yourself. Speed compiling, find bugs >>>> proactively, and fine-tune applications for parallel performance. >>>> See why Intel Parallel Studio got high marks during beta. >>>> http://p.sf.net/sfu/intel-sw-dev >>>> _______________________________________________ >>>> Jython-users mailing list >>>> Jyt...@li... >>>> https://lists.sourceforge.net/lists/listinfo/jython-users >>>> >>> >>> >> > |
|
From: Josh J. <jun...@gm...> - 2010-03-18 02:37:41
|
Hi Andy- Sorry for the delay in response. Thanks for testing the revised implementation. I am looking into these issues and I will be in touch. Best Josh Juneau jun...@gm... http://jj-blogger.blogspot.com http://www.jythonpodcast.com Twitter ID: javajuneau On Sat, Mar 13, 2010 at 3:06 AM, Andy Rose <bar...@gm...> wrote: > Sorry for the late reply! It's been a busy week. > > I'm still getting an error. I have a (serializable) Java class and a Python > class that extends it, and I've loaded the Python class (successfully) into > Java. After instantiating the Python class in Java, I'd like to make a copy > of it from Java. > > So I've tried - with the new files you've sent me - creating a new function > in the superclass (that returned null) but I overrode it in the Python > class, having it return a copy.deepcopy(pythonClassName). That didn't work, > so what I then tried was using the copy method from DeepJavaCopier, and it's > giving me a ClassNotFound error when it tries to read the object back in > (obj = in.readObject();) > > This is the first line of the error I'm getting: > java.lang.ClassNotFoundException: > org.python.proxies.MyTestClass$MyTestClass$0 > > So I'm not sure if I'm using it properly - my class is only serializable > (not cloneable), because I only want to make a deep copy of it. > > Thanks again for all your help, > Andy > > > On Tue, Mar 9, 2010 at 2:54 AM, Josh Juneau <jun...@gm...> wrote: > >> Andy- >> >> You are correct in that there were still issues with the version of >> copy.py which I previously sent to you. I think that the issues you were >> seeing are twofold. There are a couple of rules one must follow in order to >> create copies of Java objects. First, in order to be deep copyable, a Java >> object must implement java.io.Serializable. Ensure that your testClass is >> serializable. Second, if you are trying to create a shallow copy of the >> object then it must implement the java.lang.Cloneable interface and override >> the clone() method. I've attached one such Java object (Person.java) that >> should be both shallow and deep copyable via the new copy.py (which is also >> included). >> >> I found that in the previous version I sent to you , Java classes were not >> being deep copied correctly as the Python code was unable to actually create >> the copy. In order to make it work, I've re-written the deep copy >> implementation in Java code and now the copy.py uses the new Java >> implementation each time a deep copy is necessary. This seems to do the >> trick as I believe the Python deep copy implementation was encountering >> issues in translation and creating a proxy object rather than a straight >> copy. >> >> To use this new version, please place DeepJavaCopier.class, and copy.py in >> your Lib directory. Then, ensure that your Java object adheres to the rules >> mentioned above. The solution definitely could use some further testing, so >> any help would be appreciated! >> >> Thanks >> >> >> Josh Juneau >> jun...@gm... >> http://jj-blogger.blogspot.com >> http://www.jythonpodcast.com >> Twitter ID: javajuneau >> >> >> On Mon, Mar 8, 2010 at 4:28 PM, Andy Rose <bar...@gm...> wrote: >> >>> Thanks very much to both of you for the help, but with the new copy.py >>> I'm getting an error: >>> >>> raise Error('un-deep-copyable object of type %s' % type(x)) >>> copy.Error: un-deep-copyable object of type <class 'testClass.testClass'> >>> >>> testClass in this case is a very simple class containing only a single >>> integer. Any ideas why this might be happening? I can give my code if it >>> will help. >>> >>> Thanks again, >>> Barbalute >>> >>> >>> On Mon, Mar 8, 2010 at 4:08 PM, Josh Juneau <jun...@gm...> wrote: >>> >>>> Yes, there is an issue with the current version of copy.py that is being >>>> distributed with 2.5.1. You can read more about the issue on the bug >>>> tracker at http://bugs.jython.org/issue1551...but it specifically >>>> addresses issues while making copies of Java objects using copy() and >>>> deepcopy(). I am going to be checking in the attached version of copy.py >>>> which has been corrected to address the issues related to the bug report. >>>> There is also an effort taking place to convert the current version of >>>> copy.py into a Java implementation to help boost performance a bit. Please >>>> stay tuned for that version sometime in the future. >>>> >>>> If you have a moment, please drop the attached version of copy.py into >>>> your jython Lib directory and give it a try. Hopefully it will resolve your >>>> issues. If it does not, please submit another bug or add onto issue 1551. >>>> >>>> Thanks >>>> >>>> >>>> Josh Juneau >>>> jun...@gm... >>>> http://jj-blogger.blogspot.com >>>> http://www.jythonpodcast.com >>>> Twitter ID: javajuneau >>>> >>>> >>>> >>>> On Mon, Mar 8, 2010 at 1:49 PM, Barbalute <Bar...@gm...> wrote: >>>> >>>>> >>>>> As the name suggests, it seems that copy and deepcopy aren't copying >>>>> the >>>>> variables in my Java class. >>>>> >>>>> I currently have a Python class extending an existing Java abstract >>>>> class. >>>>> For various reasons, I've overwritten clone() in the Python class so >>>>> that >>>>> when the Java class calls it, it returns a deepcopy() of itself. >>>>> >>>>> This seems to properly copy the methods from the class, but the >>>>> variables >>>>> from the abstract Java class are lost in the copy, and I have no idea >>>>> why. >>>>> >>>>> In the overwritten Python clone() method, I'm able to manually copy >>>>> over the >>>>> variables, doing for example: >>>>> >>>>> x = copy.deepcopy(self) >>>>> x.name = self.name >>>>> return x >>>>> >>>>> But this shouldn't be necessary and becomes increasingly unwieldy for >>>>> classes with lots of variables. If I don't do it, though, name is not >>>>> set in >>>>> x and will return null in Java. Am I doing something wrong, or is >>>>> something >>>>> broken with copy() and deepcopy()? >>>>> >>>>> Thanks for your time. >>>>> -- >>>>> View this message in context: >>>>> http://old.nabble.com/copy-and-deepcopy-not-copying-Java-class-variables--tp27826254p27826254.html >>>>> Sent from the jython-users mailing list archive at Nabble.com. >>>>> >>>>> >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> Download Intel® Parallel Studio Eval >>>>> Try the new software tools for yourself. Speed compiling, find bugs >>>>> proactively, and fine-tune applications for parallel performance. >>>>> See why Intel Parallel Studio got high marks during beta. >>>>> http://p.sf.net/sfu/intel-sw-dev >>>>> _______________________________________________ >>>>> Jython-users mailing list >>>>> Jyt...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/jython-users >>>>> >>>> >>>> >>> >> > |