Skip to content

Commit c6e84d5

Browse files
committed
Add more nullable annotations
1 parent f2f58a2 commit c6e84d5

File tree

14 files changed

+90
-69
lines changed

14 files changed

+90
-69
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
6+
57
#if FEATURE_CTYPES
68

79
using System;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
6+
57
#if FEATURE_CTYPES
68

79
using System;
@@ -85,4 +87,4 @@ string TypeFormat {
8587
}
8688
}
8789
}
88-
#endif
90+
#endif

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
6+
57
#if FEATURE_LCG
68

79
using System;

src/core/IronPython.Modules/_ctypes_test.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
6+
57
#if FEATURE_CTYPES
68

79
using System;

src/core/IronPython.Modules/_posixsubprocess.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
6+
57
#if FEATURE_NATIVE
68

79
using IronPython.Runtime;

src/core/IronPython.Modules/binascii.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
6+
57
using System;
68
using System.IO;
79
using System.Numerics;
@@ -318,16 +320,16 @@ static void to_hex(char ch, StringBuilder s, int index) {
318320

319321
#region hqx
320322

321-
public static object a2b_hqx(object data) {
323+
public static object a2b_hqx(object? data) {
322324
throw new NotImplementedException();
323325
}
324-
public static object rledecode_hqx(object data) {
326+
public static object rledecode_hqx(object? data) {
325327
throw new NotImplementedException();
326328
}
327-
public static object rlecode_hqx(object data) {
329+
public static object rlecode_hqx(object? data) {
328330
throw new NotImplementedException();
329331
}
330-
public static object b2a_hqx(object data) {
332+
public static object b2a_hqx(object? data) {
331333
throw new NotImplementedException();
332334
}
333335

@@ -649,7 +651,7 @@ private static void ProcessSuffix(CodeContext/*!*/ context, ReadOnlySpan<byte> d
649651
}
650652

651653
private static Bytes ToBytes(this string s) {
652-
if (StringOps.TryEncodeAscii(s, out Bytes ascii))
654+
if (StringOps.TryEncodeAscii(s, out Bytes? ascii))
653655
return ascii;
654656
throw PythonOps.ValueError("string argument should contain only ASCII characters");
655657
}

src/core/IronPython.Modules/gc.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
6+
57
using System;
68
using System.Linq;
79

8-
using Microsoft.Scripting;
9-
using Microsoft.Scripting.Runtime;
10-
1110
using IronPython.Runtime;
1211
using IronPython.Runtime.Exceptions;
1312
using IronPython.Runtime.Operations;
14-
using IronPython.Runtime.Types;
13+
14+
using Microsoft.Scripting.Runtime;
1515

1616
using SpecialName = System.Runtime.CompilerServices.SpecialNameAttribute;
1717

@@ -29,7 +29,7 @@ public static class PythonGC {
2929
private static readonly object _threadholdKey = new object();
3030

3131
[SpecialName]
32-
public static void PerformModuleReload(PythonContext/*!*/ context, PythonDictionary/*!*/ dict) {
32+
public static void PerformModuleReload(PythonContext/*!*/ context, PythonDictionary/*!*/ dict) {
3333
context.SetModuleState(_threadholdKey, PythonTuple.MakeTuple(64 * 1024, 256 * 1024, 1024 * 1024));
3434
}
3535

@@ -52,7 +52,7 @@ public static int collect(CodeContext context) {
5252
return collect(context, GC.MaxGeneration);
5353
}
5454

55-
public static void set_debug(object o) {
55+
public static void set_debug(object? o) {
5656
throw PythonOps.NotImplementedError("gc.set_debug isn't implemented");
5757
}
5858

@@ -65,24 +65,24 @@ public static object[] get_objects() {
6565
}
6666

6767
public static void set_threshold(CodeContext/*!*/ context, params object[] args) {
68-
if(args.Length == 0) {
68+
if (args.Length == 0) {
6969
throw PythonOps.TypeError("set_threshold() takes at least 1 argument (0 given)");
7070
}
7171

72-
if(args.Length > 3) {
72+
if (args.Length > 3) {
7373
throw PythonOps.TypeError("set_threshold() takes at most 3 arguments ({0} given)", args.Length);
7474
}
7575

76-
if(args.Any(x => x is double)) {
76+
if (args.Any(x => x is double)) {
7777
throw PythonOps.TypeError("integer argument expected, got float");
7878
}
7979

80-
if(!args.All(x => x is int)) {
80+
if (!args.All(x => x is int)) {
8181
throw PythonOps.TypeError("an integer is required");
8282
}
8383

8484
PythonTuple current = get_threshold(context);
85-
object[] threshold = args.Take(args.Length)
85+
object?[] threshold = args.Take(args.Length)
8686
.Concat(current.ToArray().Skip(args.Length))
8787
.ToArray();
8888
SetThresholds(context, PythonTuple.MakeTuple(threshold));

src/core/IronPython.Modules/marshal.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
6+
57
using System.Collections.Generic;
68

79
using IronPython.Runtime;
@@ -14,23 +16,23 @@ public static class PythonMarshal {
1416

1517
#region Public marshal APIs
1618

17-
public static void dump(CodeContext/*!*/ context, object value, PythonIOModule._IOBase/*!*/ file, int version = PythonMarshal.version) {
19+
public static void dump(CodeContext/*!*/ context, object? value, PythonIOModule._IOBase? file, int version = PythonMarshal.version) {
1820
if (file == null) throw PythonOps.TypeError("expected file, found None");
1921

2022
file.write(context, dumps(value, version));
2123
}
2224

23-
public static object load(CodeContext/*!*/ context, PythonIOModule._IOBase/*!*/ file) {
25+
public static object load(CodeContext/*!*/ context, PythonIOModule._IOBase? file) {
2426
if (file == null) throw PythonOps.TypeError("expected file, found None");
2527

2628
return MarshalOps.GetObject(FileEnumerator(context, file));
2729
}
2830

29-
public static Bytes dumps(object value, int version = PythonMarshal.version) {
31+
public static Bytes dumps(object? value, int version = PythonMarshal.version) {
3032
return Bytes.Make(MarshalOps.GetBytes(value, version));
3133
}
3234

33-
public static object loads([BytesLike]IList<byte> bytes) {
35+
public static object loads([BytesLike, NotNone] IList<byte> bytes) {
3436
return MarshalOps.GetObject(bytes.GetEnumerator());
3537
}
3638

src/core/IronPython.Modules/math.Generated.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
6+
57
using System;
68

79
namespace IronPython.Modules {

src/core/IronPython.Modules/math.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
6+
57
using System;
68
using System.Collections;
79
using System.Collections.Generic;
810
using System.Diagnostics;
911
using System.Linq;
1012
using System.Numerics;
1113

12-
using Microsoft.Scripting;
13-
using Microsoft.Scripting.Utils;
14-
1514
using IronPython.Runtime;
1615
using IronPython.Runtime.Operations;
17-
using IronPython.Runtime.Types;
16+
17+
using Microsoft.Scripting.Utils;
1818

1919
[assembly: PythonModule("math", typeof(IronPython.Modules.PythonMath))]
2020
namespace IronPython.Modules {
@@ -78,7 +78,7 @@ private static double sum(List<double> partials) {
7878
return hi;
7979
}
8080

81-
public static double fsum(IEnumerable e) {
81+
public static double fsum([NotNone] IEnumerable e) {
8282
// msum from https://code.activestate.com/recipes/393090/
8383
var partials = new List<double>();
8484
foreach (var v in e.Cast<object>().Select(o => Converter.ConvertToDouble(o))) {
@@ -205,7 +205,7 @@ public static double log(BigInteger value) {
205205
return value.Log();
206206
}
207207

208-
public static double log(object value) {
208+
public static double log(object? value) {
209209
// CPython tries float first, then double, so we need
210210
// an explicit overload which properly matches the order here
211211
double val;
@@ -227,7 +227,7 @@ public static double log(BigInteger value, double newBase) {
227227
return Check(value.Log(newBase));
228228
}
229229

230-
public static double log(object value, double newBase) {
230+
public static double log(object? value, double newBase) {
231231
// CPython tries float first, then double, so we need
232232
// an explicit overload which properly matches the order here
233233
double val;
@@ -287,7 +287,7 @@ public static double log10(BigInteger value) {
287287
return value.Log10();
288288
}
289289

290-
public static double log10(object value) {
290+
public static double log10(object? value) {
291291
// CPython tries float first, then double, so we need
292292
// an explicit overload which properly matches the order here
293293
double val;
@@ -320,7 +320,7 @@ public static double log1p(BigInteger value) {
320320
return log(value + BigInteger.One);
321321
}
322322

323-
public static double log1p(object value) {
323+
public static double log1p(object? value) {
324324
// CPython tries float first, then double, so we need
325325
// an explicit overload which properly matches the order here
326326
double val;
@@ -353,7 +353,7 @@ public static double asinh(double x) {
353353
#endif
354354
}
355355

356-
public static double asinh(object value) {
356+
public static double asinh(object? value) {
357357
// CPython tries float first, then double, so we need
358358
// an explicit overload which properly matches the order here
359359
double val;
@@ -385,7 +385,7 @@ public static double acosh(double x) {
385385
#endif
386386
}
387387

388-
public static double acosh(object value) {
388+
public static double acosh(object? value) {
389389
// CPython tries float first, then double, so we need
390390
// an explicit overload which properly matches the order here
391391
double val;
@@ -420,7 +420,7 @@ public static double atanh(BigInteger value) {
420420
}
421421
}
422422

423-
public static double atanh(object value) {
423+
public static double atanh(object? value) {
424424
// CPython tries float first, then double, so we need
425425
// an explicit overload which properly matches the order here
426426
double val;
@@ -448,7 +448,7 @@ public static double atan2(double v0, double v1) {
448448
return Math.Atan2(v0, v1);
449449
}
450450

451-
public static object ceil(CodeContext context, object x) {
451+
public static object ceil(CodeContext context, object? x) {
452452
object val;
453453
if (PythonTypeOps.TryInvokeUnaryOperator(context, x, "__ceil__", out val)) {
454454
return val;
@@ -508,7 +508,7 @@ public static object factorial(BigInteger value) {
508508
return (int)val;
509509
}
510510

511-
public static object factorial(object value) {
511+
public static object factorial(object? value) {
512512
// CPython tries float first, then double, so we need
513513
// an explicit overload which properly matches the order here
514514
double val;
@@ -519,7 +519,7 @@ public static object factorial(object value) {
519519
}
520520
}
521521

522-
public static object floor(CodeContext context, object x) {
522+
public static object floor(CodeContext context, object? x) {
523523
object val;
524524
if (PythonTypeOps.TryInvokeUnaryOperator(context, x, "__floor__", out val)) {
525525
return val;
@@ -553,8 +553,8 @@ public static double lgamma(double v0) {
553553
return Check(v0, MathUtils.LogGamma(v0));
554554
}
555555

556-
public static object trunc(CodeContext/*!*/ context, object value) {
557-
object func;
556+
public static object? trunc(CodeContext/*!*/ context, object? value) {
557+
object? func;
558558
if (PythonOps.TryGetBoundAttr(value, "__trunc__", out func)) {
559559
return PythonOps.CallWithContext(context, func);
560560
} else {
@@ -574,7 +574,7 @@ public static bool isinf(BigInteger value) {
574574
return false;
575575
}
576576

577-
public static bool isinf(object value) {
577+
public static bool isinf(object? value) {
578578
// CPython tries float first, then double, so we need
579579
// an explicit overload which properly matches the order here
580580
double val;
@@ -592,7 +592,7 @@ public static bool isnan(BigInteger value) {
592592
return false;
593593
}
594594

595-
public static bool isnan(object value) {
595+
public static bool isnan(object? value) {
596596
// CPython tries float first, then double, so we need
597597
// an explicit overload which properly matches the order here
598598
double val;
@@ -606,7 +606,7 @@ public static double copysign(double x, double y) {
606606
return DoubleOps.CopySign(x, y);
607607
}
608608

609-
public static double copysign(object x, object y) {
609+
public static double copysign(object? x, object? y) {
610610
double val, sign;
611611
if (!Converter.TryConvertToDouble(x, out val) ||
612612
!Converter.TryConvertToDouble(y, out sign)) {
@@ -623,10 +623,10 @@ public static object gcd(BigInteger x, BigInteger y) {
623623
return res;
624624
}
625625

626-
public static object gcd(object x, object y) {
626+
public static object gcd(object? x, object? y) {
627627
return gcd(ObjectToBigInteger(x), ObjectToBigInteger(y));
628628

629-
static BigInteger ObjectToBigInteger(object x) {
629+
static BigInteger ObjectToBigInteger(object? x) {
630630
BigInteger a;
631631
switch (PythonOps.Index(x)) {
632632
case int i:

0 commit comments

Comments
 (0)