Skip to content

Commit a68871b

Browse files
authored
Prefer PythonCalls.Call (IronLanguages#1994)
1 parent 1d02728 commit a68871b

17 files changed

Lines changed: 39 additions & 29 deletions

File tree

src/core/IronPython.Modules/_csv.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ public void writerow(CodeContext/*!*/ context, object sequence) {
943943

944944
_rec.Append(_dialect.lineterminator);
945945

946-
PythonOps.CallWithContext(context, _writeline, _rec.ToString());
946+
PythonCalls.Call(context, _writeline, _rec.ToString());
947947
}
948948

949949
[Documentation(@"writerows(sequence of sequences)

src/core/IronPython.Modules/_ctypes/SimpleCData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void __init__(CodeContext/*!*/ context, object value) {
8989
}
9090

9191
if (__float__ != null) {
92-
value = PythonOps.CallWithContext(context, __float__);
92+
value = PythonCalls.Call(context, __float__);
9393
}
9494
}
9595
break;

src/core/IronPython.Modules/_datetime.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ public double timestamp() {
10651065
public static datetime strptime(CodeContext/*!*/ context, [NotNone] PythonType cls, [NotNone] string date_string, [NotNone] string format) {
10661066
var module = context.LanguageContext.GetStrptimeModule();
10671067
var _strptime_datetime = PythonOps.GetBoundAttr(context, module, "_strptime_datetime");
1068-
return (datetime)PythonOps.CallWithContext(context, _strptime_datetime, cls, date_string, format)!;
1068+
return (datetime)PythonCalls.Call(context, _strptime_datetime, cls, date_string, format)!;
10691069
}
10701070

10711071
#region IRichComparable Members
@@ -1503,7 +1503,7 @@ public virtual string tzname(object? dt) {
15031503
public PythonTuple __reduce__(CodeContext/*!*/ context) {
15041504
object? args = PythonTuple.EMPTY;
15051505
if (PythonOps.TryGetBoundAttr(context, this, "__getinitargs__", out var getinitargs)) {
1506-
args = PythonOps.CallWithContext(context, getinitargs);
1506+
args = PythonCalls.Call(context, getinitargs);
15071507
}
15081508

15091509
if (GetType() == typeof(tzinfo) ||

src/core/IronPython.Modules/_operator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public PythonTuple __reduce__(CodeContext context) {
149149
public object? Call(CodeContext/*!*/ context, object? param) {
150150
object method = PythonOps.GetBoundAttr(context, param, _name);
151151
if (_dict == null) {
152-
return PythonOps.CallWithContext(context, method, _args);
152+
return PythonCalls.Call(context, method, _args);
153153
} else {
154154
return PythonCalls.CallWithKeywordArgs(context, method, _args, _dict);
155155
}

src/core/IronPython.Modules/math.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ public static double lgamma(double v0) {
556556
public static object? trunc(CodeContext/*!*/ context, object? value) {
557557
object? func;
558558
if (PythonOps.TryGetBoundAttr(value, "__trunc__", out func)) {
559-
return PythonOps.CallWithContext(context, func);
559+
return PythonCalls.Call(context, func);
560560
} else {
561561
throw PythonOps.TypeError("type {0} doesn't define __trunc__ method", PythonOps.GetPythonTypeName(value));
562562
}

src/core/IronPython.Modules/pyexpat.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ public void ParseFile(CodeContext context, object file) {
639639
if (!PythonOps.TryGetBoundAttr(context, file, "read", out object _readMethod))
640640
throw PythonOps.TypeError("argument must have 'read' attribute");
641641

642-
object readResult = PythonOps.CallWithContext(context, _readMethod);
642+
object readResult = PythonCalls.Call(context, _readMethod);
643643
if (readResult is Bytes b) {
644644
using (var stream = new MemoryStream(b.UnsafeByteArray, writable: false)) {
645645
var settings = new XmlReaderSettings() { DtdProcessing = DtdProcessing.Parse, XmlResolver = null };

src/core/IronPython.Modules/re.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static void PerformModuleReload(PythonContext/*!*/ context, PythonDiction
4040
var module = context.GetCopyRegModule();
4141
if (module != null) {
4242
var pickle = PythonOps.GetBoundAttr(context.SharedContext, module, "pickle");
43-
PythonOps.CallWithContext(context.SharedContext, pickle, DynamicHelpers.GetPythonTypeFromType(typeof(Pattern)), dict["_pickle"]);
43+
PythonCalls.Call(context.SharedContext, pickle, DynamicHelpers.GetPythonTypeFromType(typeof(Pattern)), dict["_pickle"]);
4444
}
4545
}
4646

src/core/IronPython.Modules/time.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,13 @@ public static string strftime(CodeContext/*!*/ context, [NotNone] string format,
177177
public static object? strptime(CodeContext/*!*/ context, [NotNone] string @string) {
178178
var module = context.LanguageContext.GetStrptimeModule();
179179
var _strptime_time = PythonOps.GetBoundAttr(context, module, "_strptime_time");
180-
return PythonOps.CallWithContext(context, _strptime_time, @string);
180+
return PythonCalls.Call(context, _strptime_time, @string);
181181
}
182182

183183
public static object? strptime(CodeContext/*!*/ context, [NotNone] string @string, [NotNone] string format) {
184184
var module = context.LanguageContext.GetStrptimeModule();
185185
var _strptime_time = PythonOps.GetBoundAttr(context, module, "_strptime_time");
186-
return PythonOps.CallWithContext(context, _strptime_time, @string, format);
186+
return PythonCalls.Call(context, _strptime_time, @string, format);
187187
}
188188

189189
internal static string strftime(CodeContext/*!*/ context, string format, DateTime dt, int? microseconds, TimeZoneInfo? tzinfo = null, bool errorOnF = false) {

src/core/IronPython/Modules/_fileio.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public FileIO(CodeContext/*!*/ context, [NotNone] string name, [NotNone] string
166166
}
167167
}
168168
} else { // opener is not null
169-
object? fdobj = PythonOps.CallWithContext(context, opener, name, flags);
169+
object? fdobj = PythonCalls.Call(context, opener, name, flags);
170170
if (fdobj is int fd) {
171171
if (fd < 0) {
172172
throw PythonOps.ValueError("opener returned {0}", fd);

src/core/IronPython/Modules/_io.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ public virtual BigInteger readinto(CodeContext/*!*/ context, object buf) {
544544
object setter;
545545
if (PythonOps.TryGetBoundAttr(buf, "__setitem__", out setter)) {
546546
for (int i = 0; i < data.Count; i++) {
547-
PythonOps.CallWithContext(context, setter, i, data[i]);
547+
PythonCalls.Call(context, setter, i, data[i]);
548548
}
549549
GC.KeepAlive(this);
550550
return data.Count;
@@ -2707,7 +2707,7 @@ private object GetEncoder(CodeContext/*!*/ context) {
27072707
throw PythonOps.LookupError(_encoding);
27082708
}
27092709

2710-
_encoder = PythonOps.CallWithContext(context, factory, _errors);
2710+
_encoder = PythonCalls.Call(context, factory, _errors);
27112711
return _encoder;
27122712
}
27132713

@@ -2718,7 +2718,7 @@ private object GetDecoder(CodeContext/*!*/ context) {
27182718
throw PythonOps.LookupError(_encoding);
27192719
}
27202720

2721-
_decoder = PythonOps.CallWithContext(context, factory, _errors);
2721+
_decoder = PythonCalls.Call(context, factory, _errors);
27222722
if (_readUniversal) {
27232723
_decoder = new IncrementalNewlineDecoder(_decoder, _readTranslate, "strict");
27242724
}

0 commit comments

Comments
 (0)