[IronPython] Getting attribute of new-style bound methods overriding built-in types

Dino Viehland dinov at exchange.microsoft.com
Tue Jul 17 18:11:12 CEST 2007

Thanks for the report Seo.  I've opened bug #11760 (http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=11760).  Strangely in v2.0 on Windows this works for me but I think it's because you choose __str__ and we end up finding it in Method instead of hitting the class.  This one is actually fairly easy to fix (we just need to go to Ops.GetAttr instead of doing the direct cast to PythonFunction).  That makes it a great candidate for including in a future v1.x release as well as v2.0.

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Sanghyeon Seo
Sent: Wednesday, July 11, 2007 8:22 PM
To: Discussion of IronPython
Subject: [IronPython] Getting attribute of new-style bound methods overriding built-in types

That was mouthful. This is for 1.1. (Running the following code on
2.0a2/Mono dies inside System.Reflection.Emit. Ugh.)

class C(object):
    def __str__(self):
        return 'C'

obj = C()
getattr(obj.__str__, 'attribute', None)


TypeError: Cannot cast from source type to destination type.

This is InvalidCastException.
IronPython/Runtime/calls/Function.cs has this comment on line 906:

public sealed partial class Method (snip) {
    //??? can I type this to Function
    private object func;

Apparently you can't... The error is thrown when you cast func to
PythonFunction, I think.

Seo Sanghyeon
users mailing list
users at lists.ironpython.com

More information about the Ironpython-users mailing list