diff --git a/src/core/IronPython.Modules/_csv.cs b/src/core/IronPython.Modules/_csv.cs index e77d3b766..f442329aa 100644 --- a/src/core/IronPython.Modules/_csv.cs +++ b/src/core/IronPython.Modules/_csv.cs @@ -943,7 +943,7 @@ public void writerow(CodeContext/*!*/ context, object sequence) { _rec.Append(_dialect.lineterminator); - PythonOps.CallWithContext(context, _writeline, _rec.ToString()); + PythonCalls.Call(context, _writeline, _rec.ToString()); } [Documentation(@"writerows(sequence of sequences) diff --git a/src/core/IronPython.Modules/_ctypes/SimpleCData.cs b/src/core/IronPython.Modules/_ctypes/SimpleCData.cs index 1babc2e66..9611e0e35 100644 --- a/src/core/IronPython.Modules/_ctypes/SimpleCData.cs +++ b/src/core/IronPython.Modules/_ctypes/SimpleCData.cs @@ -89,7 +89,7 @@ public void __init__(CodeContext/*!*/ context, object value) { } if (__float__ != null) { - value = PythonOps.CallWithContext(context, __float__); + value = PythonCalls.Call(context, __float__); } } break; diff --git a/src/core/IronPython.Modules/_datetime.cs b/src/core/IronPython.Modules/_datetime.cs index 5c217e1fd..5c6bf2ea4 100644 --- a/src/core/IronPython.Modules/_datetime.cs +++ b/src/core/IronPython.Modules/_datetime.cs @@ -1065,7 +1065,7 @@ public double timestamp() { public static datetime strptime(CodeContext/*!*/ context, [NotNone] PythonType cls, [NotNone] string date_string, [NotNone] string format) { var module = context.LanguageContext.GetStrptimeModule(); var _strptime_datetime = PythonOps.GetBoundAttr(context, module, "_strptime_datetime"); - return (datetime)PythonOps.CallWithContext(context, _strptime_datetime, cls, date_string, format)!; + return (datetime)PythonCalls.Call(context, _strptime_datetime, cls, date_string, format)!; } #region IRichComparable Members @@ -1503,7 +1503,7 @@ public virtual string tzname(object? dt) { public PythonTuple __reduce__(CodeContext/*!*/ context) { object? args = PythonTuple.EMPTY; if (PythonOps.TryGetBoundAttr(context, this, "__getinitargs__", out var getinitargs)) { - args = PythonOps.CallWithContext(context, getinitargs); + args = PythonCalls.Call(context, getinitargs); } if (GetType() == typeof(tzinfo) || diff --git a/src/core/IronPython.Modules/_operator.cs b/src/core/IronPython.Modules/_operator.cs index a28695b53..bd4beffda 100644 --- a/src/core/IronPython.Modules/_operator.cs +++ b/src/core/IronPython.Modules/_operator.cs @@ -149,7 +149,7 @@ public PythonTuple __reduce__(CodeContext context) { public object? Call(CodeContext/*!*/ context, object? param) { object method = PythonOps.GetBoundAttr(context, param, _name); if (_dict == null) { - return PythonOps.CallWithContext(context, method, _args); + return PythonCalls.Call(context, method, _args); } else { return PythonCalls.CallWithKeywordArgs(context, method, _args, _dict); } diff --git a/src/core/IronPython.Modules/math.cs b/src/core/IronPython.Modules/math.cs index c2a888bd0..309d5adaa 100644 --- a/src/core/IronPython.Modules/math.cs +++ b/src/core/IronPython.Modules/math.cs @@ -556,7 +556,7 @@ public static double lgamma(double v0) { public static object? trunc(CodeContext/*!*/ context, object? value) { object? func; if (PythonOps.TryGetBoundAttr(value, "__trunc__", out func)) { - return PythonOps.CallWithContext(context, func); + return PythonCalls.Call(context, func); } else { throw PythonOps.TypeError("type {0} doesn't define __trunc__ method", PythonOps.GetPythonTypeName(value)); } diff --git a/src/core/IronPython.Modules/pyexpat.cs b/src/core/IronPython.Modules/pyexpat.cs index 0b7e9d8e5..28bf52289 100644 --- a/src/core/IronPython.Modules/pyexpat.cs +++ b/src/core/IronPython.Modules/pyexpat.cs @@ -639,7 +639,7 @@ public void ParseFile(CodeContext context, object file) { if (!PythonOps.TryGetBoundAttr(context, file, "read", out object _readMethod)) throw PythonOps.TypeError("argument must have 'read' attribute"); - object readResult = PythonOps.CallWithContext(context, _readMethod); + object readResult = PythonCalls.Call(context, _readMethod); if (readResult is Bytes b) { using (var stream = new MemoryStream(b.UnsafeByteArray, writable: false)) { var settings = new XmlReaderSettings() { DtdProcessing = DtdProcessing.Parse, XmlResolver = null }; diff --git a/src/core/IronPython.Modules/re.cs b/src/core/IronPython.Modules/re.cs index 7708204cf..cb84868f7 100644 --- a/src/core/IronPython.Modules/re.cs +++ b/src/core/IronPython.Modules/re.cs @@ -40,7 +40,7 @@ public static void PerformModuleReload(PythonContext/*!*/ context, PythonDiction var module = context.GetCopyRegModule(); if (module != null) { var pickle = PythonOps.GetBoundAttr(context.SharedContext, module, "pickle"); - PythonOps.CallWithContext(context.SharedContext, pickle, DynamicHelpers.GetPythonTypeFromType(typeof(Pattern)), dict["_pickle"]); + PythonCalls.Call(context.SharedContext, pickle, DynamicHelpers.GetPythonTypeFromType(typeof(Pattern)), dict["_pickle"]); } } diff --git a/src/core/IronPython.Modules/time.cs b/src/core/IronPython.Modules/time.cs index 1efc16f17..f98f2c457 100644 --- a/src/core/IronPython.Modules/time.cs +++ b/src/core/IronPython.Modules/time.cs @@ -177,13 +177,13 @@ public static string strftime(CodeContext/*!*/ context, [NotNone] string format, public static object? strptime(CodeContext/*!*/ context, [NotNone] string @string) { var module = context.LanguageContext.GetStrptimeModule(); var _strptime_time = PythonOps.GetBoundAttr(context, module, "_strptime_time"); - return PythonOps.CallWithContext(context, _strptime_time, @string); + return PythonCalls.Call(context, _strptime_time, @string); } public static object? strptime(CodeContext/*!*/ context, [NotNone] string @string, [NotNone] string format) { var module = context.LanguageContext.GetStrptimeModule(); var _strptime_time = PythonOps.GetBoundAttr(context, module, "_strptime_time"); - return PythonOps.CallWithContext(context, _strptime_time, @string, format); + return PythonCalls.Call(context, _strptime_time, @string, format); } internal static string strftime(CodeContext/*!*/ context, string format, DateTime dt, int? microseconds, TimeZoneInfo? tzinfo = null, bool errorOnF = false) { diff --git a/src/core/IronPython/Modules/_fileio.cs b/src/core/IronPython/Modules/_fileio.cs index 2560a5eda..e599bfa34 100644 --- a/src/core/IronPython/Modules/_fileio.cs +++ b/src/core/IronPython/Modules/_fileio.cs @@ -166,7 +166,7 @@ public FileIO(CodeContext/*!*/ context, [NotNone] string name, [NotNone] string } } } else { // opener is not null - object? fdobj = PythonOps.CallWithContext(context, opener, name, flags); + object? fdobj = PythonCalls.Call(context, opener, name, flags); if (fdobj is int fd) { if (fd < 0) { throw PythonOps.ValueError("opener returned {0}", fd); diff --git a/src/core/IronPython/Modules/_io.cs b/src/core/IronPython/Modules/_io.cs index 59bd726ad..6ebf39aa1 100644 --- a/src/core/IronPython/Modules/_io.cs +++ b/src/core/IronPython/Modules/_io.cs @@ -544,7 +544,7 @@ public virtual BigInteger readinto(CodeContext/*!*/ context, object buf) { object setter; if (PythonOps.TryGetBoundAttr(buf, "__setitem__", out setter)) { for (int i = 0; i < data.Count; i++) { - PythonOps.CallWithContext(context, setter, i, data[i]); + PythonCalls.Call(context, setter, i, data[i]); } GC.KeepAlive(this); return data.Count; @@ -2707,7 +2707,7 @@ private object GetEncoder(CodeContext/*!*/ context) { throw PythonOps.LookupError(_encoding); } - _encoder = PythonOps.CallWithContext(context, factory, _errors); + _encoder = PythonCalls.Call(context, factory, _errors); return _encoder; } @@ -2718,7 +2718,7 @@ private object GetDecoder(CodeContext/*!*/ context) { throw PythonOps.LookupError(_encoding); } - _decoder = PythonOps.CallWithContext(context, factory, _errors); + _decoder = PythonCalls.Call(context, factory, _errors); if (_readUniversal) { _decoder = new IncrementalNewlineDecoder(_decoder, _readTranslate, "strict"); } diff --git a/src/core/IronPython/Runtime/ClrModule.cs b/src/core/IronPython/Runtime/ClrModule.cs index ea4605735..6d3e45757 100644 --- a/src/core/IronPython/Runtime/ClrModule.cs +++ b/src/core/IronPython/Runtime/ClrModule.cs @@ -678,9 +678,9 @@ public object Call(CodeContext context, params object[] args) { ValidateArgs(args); if (_inst != null) { - return PythonOps.CallWithContext(context, _func, ArrayUtils.Insert(_inst, args)); + return PythonCalls.Call(context, _func, ArrayUtils.Insert(_inst, args)); } else { - return PythonOps.CallWithContext(context, _func, args); + return PythonCalls.Call(context, _func, args); } } @@ -762,7 +762,7 @@ private void ValidateReturn(object ret) { #region ICallableWithCodeContext Members [SpecialName] public object Call(CodeContext context, params object[] args) { - object ret = PythonOps.CallWithContext( + object ret = PythonCalls.Call( context, _func, _inst != null ? ArrayUtils.Insert(_inst, args) : args); diff --git a/src/core/IronPython/Runtime/Map.cs b/src/core/IronPython/Runtime/Map.cs index 02cba18ae..25c793155 100644 --- a/src/core/IronPython/Runtime/Map.cs +++ b/src/core/IronPython/Runtime/Map.cs @@ -56,7 +56,7 @@ public Map(CodeContext context, object? func, [NotNone] params object[] iterable public bool MoveNext() { if (_enumerator is null) { if (_enumerators.All(x => x.MoveNext())) { - Current = PythonOps.CallWithContext(_context, _func, _enumerators.Select(x => x.Current).ToArray()); + Current = PythonCalls.Call(_context, _func, _enumerators.Select(x => x.Current).ToArray()); return true; } } else if (_enumerator.MoveNext()) { diff --git a/src/core/IronPython/Runtime/Operations/ArrayOps.cs b/src/core/IronPython/Runtime/Operations/ArrayOps.cs index 33511c281..c0b9e51b1 100644 --- a/src/core/IronPython/Runtime/Operations/ArrayOps.cs +++ b/src/core/IronPython/Runtime/Operations/ArrayOps.cs @@ -60,7 +60,7 @@ public static object __new__(CodeContext context, PythonType pythonType, object if (!PythonOps.TryGetBoundAttr(items, "__len__", out object? lenFunc)) throw PythonOps.TypeErrorForBadInstance("expected object with __len__ function, got {0}", items); - int len = context.LanguageContext.ConvertToInt32(PythonOps.CallWithContext(context, lenFunc)); + int len = context.LanguageContext.ConvertToInt32(PythonCalls.Call(context, lenFunc)); Array res = @base == 0 ? Array.CreateInstance(type, len) : Array.CreateInstance(type, [len], [@base]); diff --git a/src/core/IronPython/Runtime/Operations/ObjectOps.cs b/src/core/IronPython/Runtime/Operations/ObjectOps.cs index 8c8ac2d2a..2e2501e39 100644 --- a/src/core/IronPython/Runtime/Operations/ObjectOps.cs +++ b/src/core/IronPython/Runtime/Operations/ObjectOps.cs @@ -140,7 +140,7 @@ public static object __new__(CodeContext/*!*/ context, PythonType cls, [ParamDic // A derived class overrode __reduce__ but not __reduce_ex__, so call // specialized __reduce__ instead of generic __reduce_ex__. // (see the "The __reduce_ex__ API" section of PEP 307) - return PythonOps.CallWithContext(context, myReduce, self)!; + return PythonCalls.Call(context, myReduce, self)!; } } @@ -325,7 +325,7 @@ private static HashSet NativelyPickleableTypes { internal static object? ReduceProtocol0(CodeContext/*!*/ context, object self) { var copyreg = context.LanguageContext.GetCopyRegModule(); var _reduce_ex = PythonOps.GetBoundAttr(context, copyreg, "_reduce_ex"); - return PythonOps.CallWithContext(context, _reduce_ex, self, 0); + return PythonCalls.Call(context, _reduce_ex, self, 0); } /// @@ -347,7 +347,7 @@ private static PythonTuple ReduceProtocol2(CodeContext/*!*/ context, object self if (PythonOps.TryGetBoundAttr(context, myType, "__getnewargs__", out object? getNewArgsCallable)) { // TypeError will bubble up if __getnewargs__ isn't callable - if (!(PythonOps.CallWithContext(context, getNewArgsCallable, self) is PythonTuple newArgs)) { + if (!(PythonCalls.Call(context, getNewArgsCallable, self) is PythonTuple newArgs)) { throw PythonOps.TypeError("__getnewargs__ should return a tuple"); } funcArgs = new object[1 + newArgs.Count]; diff --git a/src/core/IronPython/Runtime/Operations/PythonOps.cs b/src/core/IronPython/Runtime/Operations/PythonOps.cs index d4dcb62df..953a6861c 100644 --- a/src/core/IronPython/Runtime/Operations/PythonOps.cs +++ b/src/core/IronPython/Runtime/Operations/PythonOps.cs @@ -969,6 +969,7 @@ internal static bool TryInvokeLengthHint(CodeContext context, object? sequence, return false; } + [Obsolete("Use PythonCalls.Call")] public static object? CallWithContext(CodeContext/*!*/ context, object? func, params object?[] args) { return PythonCalls.Call(context, func, args); } @@ -979,9 +980,10 @@ internal static bool TryInvokeLengthHint(CodeContext context, object? sequence, /// that supports calling with 'this'. If not, the 'this' object is dropped /// and a normal call is made. /// + [Obsolete("Use PythonCalls.Call")] public static object? CallWithContextAndThis(CodeContext/*!*/ context, object? func, object? instance, params object?[] args) { // drop the 'this' and make the call - return CallWithContext(context, func, args); + return PythonCalls.Call(context, func, args); } [Obsolete("Use ObjectOperations instead")] @@ -995,7 +997,7 @@ internal static bool TryInvokeLengthHint(CodeContext context, object? sequence, foreach (object? arg in PythonOps.GetCollection(argsTuple)) largs.Add(arg); } - return CallWithContext(context, func, largs.ToArray()); + return PythonCalls.Call(context, func, largs.ToArray()); } else { List largs; @@ -1195,10 +1197,18 @@ public static bool TryDeleteUserDescriptor(object o, object instance) { out _); } + public static object? Invoke(CodeContext/*!*/ context, object? target, string name) { + return PythonCalls.Call(context, PythonOps.GetBoundAttr(context, target, name)); + } + public static object? Invoke(CodeContext/*!*/ context, object? target, string name, object? arg0) { return PythonCalls.Call(context, PythonOps.GetBoundAttr(context, target, name), arg0); } + public static object? Invoke(CodeContext/*!*/ context, object? target, string name, object? arg0, object? arg1) { + return PythonCalls.Call(context, PythonOps.GetBoundAttr(context, target, name), arg0, arg1); + } + public static object? Invoke(CodeContext/*!*/ context, object? target, string name, params object?[] args) { return PythonCalls.Call(context, PythonOps.GetBoundAttr(context, target, name), args); } @@ -3420,7 +3430,7 @@ public static void Warn(CodeContext/*!*/ context, PythonType category, string me if (warn == null) { PythonOps.PrintWithDest(context, pc.SystemStandardError, $"warning: {category.Name}: {message}"); } else { - PythonOps.CallWithContext(context, warn, message, category); + PythonCalls.Call(context, warn, message, category); } } @@ -3436,7 +3446,7 @@ public static void ShowWarning(CodeContext/*!*/ context, PythonType category, st if (warn == null) { PythonOps.PrintWithDest(context, pc.SystemStandardError, $"{filename}:{lineNo}: {category.Name}: {message}"); } else { - PythonOps.CallWithContext(context, warn, message, category, filename ?? "", lineNo); + PythonCalls.Call(context, warn, message, category, filename ?? "", lineNo); } } diff --git a/src/core/IronPython/Runtime/Operations/PythonTypeOps.cs b/src/core/IronPython/Runtime/Operations/PythonTypeOps.cs index a96a60892..9a28f5be3 100644 --- a/src/core/IronPython/Runtime/Operations/PythonTypeOps.cs +++ b/src/core/IronPython/Runtime/Operations/PythonTypeOps.cs @@ -64,10 +64,10 @@ internal static object CallParams(CodeContext/*!*/ context, PythonType cls, para } internal static object CallWorker(CodeContext/*!*/ context, PythonType dt, object[] args) { - object newObject = PythonOps.CallWithContext(context, GetTypeNew(context, dt), ArrayUtils.Insert(dt, args)); + object newObject = PythonCalls.Call(context, GetTypeNew(context, dt), ArrayUtils.Insert(dt, args)); if (ShouldInvokeInit(dt, DynamicHelpers.GetPythonType(newObject), args.Length)) { - PythonOps.CallWithContext(context, GetInitMethod(context, dt, newObject), args); + PythonCalls.Call(context, GetInitMethod(context, dt, newObject), args); AddFinalizer(context, dt, newObject); } diff --git a/src/core/IronPython/Runtime/Types/PythonType.cs b/src/core/IronPython/Runtime/Types/PythonType.cs index 0fb363fc7..3a4f4ab2e 100644 --- a/src/core/IronPython/Runtime/Types/PythonType.cs +++ b/src/core/IronPython/Runtime/Types/PythonType.cs @@ -3127,7 +3127,7 @@ public object SetAttr(CallSite site, object self, TValue value) { object res; if (_slot.TryGetValue(_context, self, ipo.PythonType, out res)) { - return PythonOps.CallWithContext(_context, res, _name, value); + return PythonCalls.Call(_context, res, _name, value); } return TypeError(ipo);