Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/scripts/generate_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def simple_op_worker(cw, t, arg_t, name):
)

def enter_multiarg_op(cw, t, name):
cw.enter_block('public %s %s([NotNone] params object[]/*!*/ sets)' % (t, name))
cw.enter_block('public %s %s([NotNone] params object[] sets)' % (t, name))

def union_multiarg(cw, mutable):
t = get_type(mutable)
Expand Down
10 changes: 5 additions & 5 deletions src/core/IronPython.Modules/IterTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public class chain : IterBase {

private chain() { }

public chain(params object[] iterables) {
public chain([NotNone] params object[] iterables) {
SetInnerEnumerator(PythonTuple.MakeTuple(iterables));
}

Expand Down Expand Up @@ -667,15 +667,15 @@ public class zip_longest : IEnumerator {
private readonly object _fill;
private PythonTuple _current;

public zip_longest(params object[] iterables) {
public zip_longest([NotNone] params object[] iterables) {
_iters = new IEnumerator[iterables.Length];

for (int i = 0; i < iterables.Length; i++) {
_iters[i] = PythonOps.GetEnumerator(iterables[i]);
}
}

public zip_longest([ParamDictionary] IDictionary<object, object> paramDict, params object[] iterables) {
public zip_longest([ParamDictionary] IDictionary<object, object> paramDict, [NotNone] params object[] iterables) {
object fill;

if (paramDict.TryGetValue("fillvalue", out fill)) {
Expand Down Expand Up @@ -762,12 +762,12 @@ private static Exception UnexpectedKeywordArgument(IDictionary<object, object> p
public class product : IterBase {
private PythonTuple[] tuples;

public product(CodeContext context, params object[] iterables) {
public product(CodeContext context, [NotNone] params object[] iterables) {
tuples = ArrayUtils.ConvertAll(iterables, x => new PythonTuple(PythonOps.GetEnumerator(x)));
InnerEnumerator = Yielder(tuples);
}

public product(CodeContext context, [ParamDictionary] IDictionary<object, object> paramDict, params object[] iterables) {
public product(CodeContext context, [ParamDictionary] IDictionary<object, object> paramDict, [NotNone] params object[] iterables) {
object repeat;
int iRepeat = 1;
if (paramDict.TryGetValue("repeat", out repeat)) {
Expand Down
51 changes: 25 additions & 26 deletions src/core/IronPython.Modules/ResourceMetaPathImporter.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;

using IronPython.Runtime;
using IronPython.Runtime.Exceptions;
using IronPython.Zlib;

using Microsoft.Scripting;
using Microsoft.Scripting.Runtime;

Expand Down Expand Up @@ -68,7 +74,7 @@ fully qualified (dotted) module name. It returns the importer
The optional 'path' argument is ignored -- it's there for compatibility
with the importer protocol."
)]
public object find_module(CodeContext /*!*/ context, string fullname, params object[] args) {
public object find_module(CodeContext /*!*/ context, string fullname, [NotNone] params object[] args) {
var packedName = MakeFilename(fullname);

foreach (var entry in SearchOrder) {
Expand Down Expand Up @@ -131,8 +137,7 @@ public object load_module(CodeContext /*!*/ context, string fullname) {
modules.Add(fullname, mod);
try {
script.Run(mod.Scope);
}
catch (Exception) {
} catch (Exception) {
modules.Remove(fullname);
throw;
}
Expand Down Expand Up @@ -175,8 +180,7 @@ private byte[] GetCodeFromData(CodeContext /*!*/ context, bool isbytecode, Packe
if (data != null) {
if (isbytecode) {
// would put in code to unmarshal the bytecode here...
}
else {
} else {
code = data;
}
}
Expand Down Expand Up @@ -221,8 +225,8 @@ public static PackedResourceInfo Create(string fullName, int compress,
#if DEBUG
public override string ToString() {
var sizeDesc = String.Format("{0} bytes", _fileSize);
if (Convert.ToDouble(_fileSize)/1024.0 > 1.0)
sizeDesc = String.Format("{0} KB", Math.Round(Convert.ToDouble(_fileSize)/1024.0, 1));
if (Convert.ToDouble(_fileSize) / 1024.0 > 1.0)
sizeDesc = String.Format("{0} KB", Math.Round(Convert.ToDouble(_fileSize) / 1024.0, 1));
return String.Format("{0} ({1})", FullName, sizeDesc);
}
#endif
Expand Down Expand Up @@ -259,26 +263,25 @@ where isPyFile
let path = lineage.Take(lineage.Length - 1).ToArray()
orderby fileName
select new {
name = fileName,
path,
dottedPath = String.Join(".", path),
entry
};
name = fileName,
path,
dottedPath = String.Join(".", path),
entry
};
var moduleContents =
from source in parsedSources
orderby source.dottedPath
group source by source.dottedPath
into moduleGroup
select new {
moduleGroup.Key,
Items = moduleGroup.Select(item => item.entry).ToArray()
};
moduleGroup.Key,
Items = moduleGroup.Select(item => item.entry).ToArray()
};
modules = moduleContents.ToDictionary(
moduleGroup => moduleGroup.Key,
moduleGroup => moduleGroup.Items);
return true;
}
catch (Exception exception) {
} catch (Exception exception) {
files = null;
modules = null;
unpackingError = String.Format("{0}: {1}", exception.GetType().Name, exception.Message);
Expand Down Expand Up @@ -310,7 +313,7 @@ private bool ReadZipDirectory(out IDictionary<string, PackedResourceInfo> result
var endofCentralDir = new byte[22];

reader.BaseStream.Seek(-22, SeekOrigin.End);
var headerPosition = (int) reader.BaseStream.Position;
var headerPosition = (int)reader.BaseStream.Position;
if (reader.Read(endofCentralDir, 0, 22) != 22) {
unpackingError = "Can't read ZIP resource: Invalid ZIP Directory.";
return false;
Expand All @@ -332,8 +335,7 @@ private bool ReadZipDirectory(out IDictionary<string, PackedResourceInfo> result
.ToDictionary(entry => entry.FullName);
return true;
}
}
catch (Exception exception) {
} catch (Exception exception) {
unpackingError = String.Format("{0}: {1}", exception.GetType().Name, exception.Message);
return false;
}
Expand Down Expand Up @@ -410,26 +412,23 @@ public bool GetData(PackedResourceInfo tocEntry, out byte[] result, out string u
byte[] rawData;
try {
rawData = reader.ReadBytes(compress == 0 ? dataSize : dataSize + 1);
}
catch {
} catch {
unpackingError = "Can't read data";
return false;
}

if (compress != 0) {
rawData[dataSize] = (byte) 'Z';
rawData[dataSize] = (byte)'Z';
}

result = compress == 0 ? rawData : ZlibModule.Decompress(rawData, -15);
return true;
}
}
catch (Exception exception) {
} catch (Exception exception) {
unpackingError = String.Format("{0}: {1}", exception.GetType().Name, exception.Message);
return false;
}
}
}

}
}
20 changes: 12 additions & 8 deletions src/core/IronPython.Modules/SimpleSignalState.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IronPython.Runtime;
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

#nullable enable

#if FEATURE_PROCESS

using System;

using IronPython.Runtime;

namespace IronPython.Modules {
public static partial class PythonSignal {
internal class SimpleSignalState : PythonSignalState {
Expand All @@ -14,9 +18,9 @@ public SimpleSignalState(PythonContext pc)
Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress);
}

private void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e) {
private void Console_CancelKeyPress(object? sender, ConsoleCancelEventArgs e) {
int pySignal;
switch(e.SpecialKey) {
switch (e.SpecialKey) {
case ConsoleSpecialKey.ControlC:
pySignal = SIGINT;
break;
Expand All @@ -28,7 +32,7 @@ private void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e) {
default:
throw new InvalidOperationException("unreachable");
}

lock (PySignalToPyHandler) {
if (PySignalToPyHandler[pySignal].GetType() == typeof(int)) {
int tempId = (int)PySignalToPyHandler[pySignal];
Expand Down
23 changes: 13 additions & 10 deletions src/core/IronPython.Modules/_bisect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

#nullable enable

using System;
using System.Collections;
using System.Reflection;
Expand Down Expand Up @@ -29,9 +31,9 @@ common approach.

#region Private Implementation Details

private static int InternalBisectLeft(CodeContext/*!*/ context, PythonList list, object item, int lo, int hi) {
private static int InternalBisectLeft(CodeContext/*!*/ context, PythonList list, object? item, int lo, int hi) {
int mid;
object litem;
object? litem;

if (lo < 0) {
throw PythonOps.ValueError("lo must be non-negative");
Expand All @@ -52,7 +54,7 @@ private static int InternalBisectLeft(CodeContext/*!*/ context, PythonList list,
return lo;
}

private static int InternalBisectLeft(CodeContext/*!*/ context, object list, object item, int lo, int hi) {
private static int InternalBisectLeft(CodeContext/*!*/ context, object? list, object? item, int lo, int hi) {
int mid;
object litem;

Expand All @@ -63,6 +65,7 @@ private static int InternalBisectLeft(CodeContext/*!*/ context, object list, obj
if (hi == -1) {
hi = PythonOps.Length(list);
}

IComparer comparer = context.LanguageContext.GetLtComparer(GetComparisonType(context, list));
while (lo < hi) {
mid = (int)(((long)lo + hi) / 2);
Expand All @@ -75,8 +78,8 @@ private static int InternalBisectLeft(CodeContext/*!*/ context, object list, obj
return lo;
}

private static int InternalBisectRight(CodeContext/*!*/ context, PythonList list, object item, int lo, int hi) {
object litem;
private static int InternalBisectRight(CodeContext/*!*/ context, PythonList list, object? item, int lo, int hi) {
object? litem;
int mid;

if (lo < 0) {
Expand All @@ -98,7 +101,7 @@ private static int InternalBisectRight(CodeContext/*!*/ context, PythonList list
return lo;
}

private static int InternalBisectRight(CodeContext/*!*/ context, object list, object item, int lo, int hi) {
private static int InternalBisectRight(CodeContext/*!*/ context, object list, object? item, int lo, int hi) {
object litem;
int mid;

Expand All @@ -122,7 +125,7 @@ private static int InternalBisectRight(CodeContext/*!*/ context, object list, ob
return lo;
}

private static Type GetComparisonType(CodeContext/*!*/ context, object a) {
private static Type GetComparisonType(CodeContext/*!*/ context, object? a) {
if (PythonOps.Length(a) > 0) {
// use the 1st index to determine the type - we're assuming lists are
// homogeneous
Expand Down Expand Up @@ -183,7 +186,7 @@ before the leftmost x already there.
Optional args lo (default 0) and hi (default len(a)) bound the
slice of a to be searched.
")]
public static object bisect_left(CodeContext/*!*/ context, object a, object x, int lo = 0, int hi = -1) {
public static object bisect_left(CodeContext/*!*/ context, object? a, object? x, int lo = 0, int hi = -1) {
if (a is PythonList l && l.GetType() == typeof(PythonList)) {
return InternalBisectLeft(context, l, x, lo, hi);
}
Expand All @@ -201,7 +204,7 @@ public static object bisect_left(CodeContext/*!*/ context, object a, object x, i
Optional args lo (default 0) and hi (default len(a)) bound the
slice of a to be searched.
")]
public static void InsortRight(CodeContext/*!*/ context, object a, object x, int lo=0, int hi=-1) {
public static void InsortRight(CodeContext/*!*/ context, object a, object x, int lo = 0, int hi = -1) {
if (a is PythonList l && l.GetType() == typeof(PythonList)) {
l.Insert(InternalBisectRight(context, l, x, lo, hi), x);
return;
Expand All @@ -227,7 +230,7 @@ public static void InsortRight(CodeContext/*!*/ context, object a, object x, int
Optional args lo (default 0) and hi (default len(a)) bound the
slice of a to be searched.
")]
public static void insort_left(CodeContext/*!*/ context, object a, object x, int lo=0, int hi=-1) {
public static void insort_left(CodeContext/*!*/ context, object? a, object? x, int lo = 0, int hi = -1) {
if (a is PythonList l && l.GetType() == typeof(PythonList)) {
l.Insert(InternalBisectLeft(context, l, x, lo, hi), x);
return;
Expand Down
Loading