Exemplo n.º 1
0
        public static void AddRemoveEventHelper(object method, IPythonObject instance, object eventValue, string name)
        {
            object callable = method;

            // TODO: dt gives us a PythonContext which we should use
            PythonType dt = instance.PythonType;

            if (method is PythonTypeSlot dts)
            {
                if (!dts.TryGetValue(DefaultContext.Default, instance, dt, out callable))
                {
                    throw PythonOps.AttributeErrorForMissingAttribute(dt.Name, name);
                }
            }

            if (!PythonOps.IsCallable(DefaultContext.Default, callable))
            {
                throw PythonOps.TypeError("Expected callable value for {0}, but found {1}", name.ToString(),
                                          PythonOps.GetPythonTypeName(method));
            }

            PythonCalls.Call(callable, eventValue);
        }