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

Sanghyeon Seo sanxiyn at gmail.com
Wed Jul 11 20:21:42 PDT 2007


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)

Result:

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


More information about the users mailing list