[IronPython] Magic methods on CLR types

Jeffrey Sax jeffrey at extremeoptimization.com
Wed Dec 2 15:13:54 PST 2009


That works, even for generic types! Thank you.

 

I did notice that __repr__ (and possibly others) is not picked up unless I
add ExtensionType attributes for each public subtype of a base type that I'm
extending. My guess is that IronPython already supplies a default
implementation for these, so there is no need to look up in the hierarchy.
This is understandable but somewhat unexpected.

 

Is there a way to assign Python-friendly names to CLR types by extension?
I.e. get the same effect as if a PythonTypeAttribute was applied to the
original class?

 

Thanks,

 

Jeffrey

 

From: users-bounces at lists.ironpython.com
[mailto:users-bounces at lists.ironpython.com] On Behalf Of Dino Viehland
Sent: Tuesday, December 01, 2009 8:57 PM
To: Discussion of IronPython
Subject: Re: [IronPython] Magic methods on CLR types

 

If you want IronPython to recognize them you just need to create an assembly
w/ ExtensionTypeAttribute and have it point at the extended and extending
types.  Then the assembly needs to be loaded into the ScriptRuntime using
ScriptRuntime.LoadAssembly.

 

We still need to figure out our story for recognizing and importing normal
.NET extension methods that C# supports.

 

From: users-bounces at lists.ironpython.com
[mailto:users-bounces at lists.ironpython.com] On Behalf Of Jeffrey Sax
Sent: Tuesday, December 01, 2009 5:27 PM
To: 'Discussion of IronPython'
Subject: [IronPython] Magic methods on CLR types

 

Is there a way to add magic methods like __repr__, __call__, etc. to CLR
types?

 

1.       Can it be done in the external CLR assembly without polluting the
API for other languages? If so, how?

2.       Can it be done using F# style type augmentations by redefining such
methods on the Python type corresponding to the CLR type? If so, how?

3.       If neither of these alternatives is possible, is there a third way?

 

Thanks!

 

Jeffrey Sax

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


More information about the Users mailing list