[IronPython] List<Python Class>

Dino Viehland dinov at exchange.microsoft.com
Sat May 3 00:15:11 PDT 2008


I think ultimately we want to unify pickle and .NET serialization so that this works seamless.  That'd be that ISerializable object's would get a magically _reduce__ or __reduce_ex__ methods (and appropriate __new__ methods I guess).  Also Python classes that implement the protocols for pickling would also be serializable.

I've opened a task to track this (http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=16415) but I agree with your assessment - currently remoting of Python objects doesn't look very feasible.  I'd encourage you and anyone else to vote on this if you're interested in us providing this natively.

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Paul Turbett
Sent: Friday, May 02, 2008 10:51 PM
To: Discussion of IronPython
Subject: Re: [IronPython] List<Python Class>

No, not really. I recently looked into serializing IPY class instances from C# in a hosting environment. I got it to work using some custom serialization code. Look into ISerializationSurrogate - I made a class that derives from it to make a custom Python object serializer. The python engine still needs the python class type to be define and "compiled" to be able to re-build the objects. It's a bit curly and ugly, and I'm still not sure what gotchas are lying in wait :)

L8r, Paul

Matthew Barnard wrote:
Ahhh interesting. It doesn't look good for remoting then ;)

On Fri, May 2, 2008 at 10:17 PM, Curt Hagenlocher <curt at hagenlocher.org<mailto:curt at hagenlocher.org>> wrote:
Well in the example I gave, the type of class foo would genrally be something like  IronPython.NewTypes.System.Object_1$2.  There's not going to be any "native" CLR code to which you can pass a List<IronPython.NewTypes.System.Object_1$2>, and if you're passing the data to other Python code, you may as well do it as a Python list or tuple.  It's the "dynamic" thing to do :).

List<IronPython.NewTypes.System.Object_1$2> isn't even type-safe for Python classes because IronPython maintains a cache of generated types and will reuse a type it has previously generated for any new class you define that's compatible with a previously-defined class.


On Fri, May 2, 2008 at 9:58 PM, Matthew Barnard <m.stephen.barnard at gmail.com<mailto:m.stephen.barnard at gmail.com>> wrote:
Thanks Curt, in C# I use generics (list & dict) containing class instances quite often. Is there a caveat to the dynamic typing that I'm missing?


On Fri, May 2, 2008 at 7:52 PM, Curt Hagenlocher <curt at hagenlocher.org<mailto:curt at hagenlocher.org>> wrote:
This will get you a CLR type directly from your class object:

class foo(object):
    pass
theType = clr.GetClrType(foo)

What use do you have for creating a generic with the resulting (dynamically-generated) type?
On Fri, May 2, 2008 at 6:30 PM, Matthew Barnard <m.stephen.barnard at gmail.com<mailto:m.stephen.barnard at gmail.com>> wrote:
Is the following the only way to create a generic containing a python class?


from System.Collections.Generic import List
from System import Type

class Foo:
    >>class stuff<<

l = List[Type.GetType(Foo())]()


I assume this is the nature of dynamic typing, but is there a way to get the type from the classobj, and not an instance?
_______________________________________________
Users mailing list
Users at lists.ironpython.com<mailto:Users at lists.ironpython.com>
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


_______________________________________________
Users mailing list
Users at lists.ironpython.com<mailto:Users at lists.ironpython.com>
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


--
___________________________
Matthew Barnard
602 540 0652
_______________________________________________
Users mailing list
Users at lists.ironpython.com<mailto:Users at lists.ironpython.com>
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


_______________________________________________
Users mailing list
Users at lists.ironpython.com<mailto:Users at lists.ironpython.com>
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



--
___________________________
Matthew Barnard
602 540 0652






________________________________






_______________________________________________

Users mailing list

Users at lists.ironpython.com<mailto:Users at lists.ironpython.com>

http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ironpython.com/pipermail/users-ironpython.com/attachments/20080503/15a330e9/attachment.htm>


More information about the Users mailing list