Skip to content

Commit 616b49e

Browse files
committed
Code cleanup
1 parent 95e3048 commit 616b49e

500 files changed

Lines changed: 94651 additions & 105786 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

IronPythonAnalyzer/IronPythonAnalyzer/IronPythonAnalyzerAnalyzer.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
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-
using System;
6-
using System.Collections.Generic;
75
using System.Collections.Immutable;
86
using System.Linq;
9-
using System.Threading;
7+
108
using Microsoft.CodeAnalysis;
11-
using Microsoft.CodeAnalysis.CSharp;
12-
using Microsoft.CodeAnalysis.CSharp.Syntax;
139
using Microsoft.CodeAnalysis.Diagnostics;
1410
using Microsoft.CodeAnalysis.Operations;
1511

Src/IronPython.Modules/IterTools.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
using System.Numerics;
99
using System.Runtime.InteropServices;
1010

11-
using Microsoft.Scripting;
12-
using Microsoft.Scripting.Runtime;
13-
using Microsoft.Scripting.Utils;
14-
1511
using IronPython.Runtime;
1612
using IronPython.Runtime.Binding;
1713
using IronPython.Runtime.Exceptions;
1814
using IronPython.Runtime.Operations;
1915
using IronPython.Runtime.Types;
2016

17+
using Microsoft.Scripting;
18+
using Microsoft.Scripting.Runtime;
19+
using Microsoft.Scripting.Utils;
20+
2121
[assembly: PythonModule("itertools", typeof(IronPython.Modules.PythonIterTools))]
2222
namespace IronPython.Modules {
2323
public static class PythonIterTools {
@@ -219,7 +219,7 @@ private static void EnsureIterator(CodeContext/*!*/ context, object iter) {
219219
if (iter == null ||
220220
!PythonOps.HasAttr(context, iter, "__iter__") &&
221221
!PythonOps.HasAttr(context, iter, "__getitem__")) {
222-
throw PythonOps.TypeError("'{0}' object is not iterable", PythonOps.GetPythonTypeName(iter));
222+
throw PythonOps.TypeError("'{0}' object is not iterable", PythonOps.GetPythonTypeName(iter));
223223
}
224224
}
225225

@@ -262,13 +262,13 @@ public count(BigInteger start) {
262262
InnerEnumerator = BigIntYielder(this, start, 1);
263263
}
264264

265-
public count(int start=0, int step=1) {
265+
public count(int start = 0, int step = 1) {
266266
_curInt = start;
267267
_step = step;
268268
InnerEnumerator = IntYielder(this, start, step);
269269
}
270270

271-
public count([DefaultParameterValue(0)]int start, BigInteger step) {
271+
public count([DefaultParameterValue(0)] int start, BigInteger step) {
272272
_curInt = start;
273273
_step = step;
274274
InnerEnumerator = IntYielder(this, start, step);
@@ -286,7 +286,7 @@ public count(BigInteger start, BigInteger step) {
286286
InnerEnumerator = BigIntYielder(this, start, step);
287287
}
288288

289-
public count(CodeContext/*!*/ context, [DefaultParameterValue(0)]object start, [DefaultParameterValue(1)]object step) {
289+
public count(CodeContext/*!*/ context, [DefaultParameterValue(0)] object start, [DefaultParameterValue(1)] object step) {
290290
EnsureNumeric(context, start);
291291
EnsureNumeric(context, step);
292292
_cur = start;
@@ -301,7 +301,7 @@ private static void EnsureNumeric(CodeContext/*!*/ context, object num) {
301301
if (num == null ||
302302
!PythonOps.HasAttr(context, num, "__int__") &&
303303
!PythonOps.HasAttr(context, num, "__float__")) {
304-
throw PythonOps.TypeError("a number is required");
304+
throw PythonOps.TypeError("a number is required");
305305
}
306306
}
307307

@@ -517,9 +517,9 @@ private IEnumerator<object> Yielder(IEnumerator iter) {
517517
if (MoveNextHelper(iter)) {
518518
while (!_fFinished) {
519519
while (PythonContext.Equal(GetKey(iter.Current), curKey)) {
520-
if (!MoveNextHelper(iter)) {
521-
_fFinished = true;
522-
yield break;
520+
if (!MoveNextHelper(iter)) {
521+
_fFinished = true;
522+
yield break;
523523
}
524524
}
525525
curKey = GetKey(iter.Current);
@@ -531,9 +531,9 @@ private IEnumerator<object> Yielder(IEnumerator iter) {
531531
private IEnumerator<object> Grouper(IEnumerator iter, object curKey) {
532532
while (PythonContext.Equal(GetKey(iter.Current), curKey)) {
533533
yield return iter.Current;
534-
if (!MoveNextHelper(iter)) {
535-
_fFinished = true;
536-
yield break;
534+
if (!MoveNextHelper(iter)) {
535+
_fFinished = true;
536+
yield break;
537537
}
538538
}
539539
}
@@ -658,7 +658,7 @@ public zip_longest(params object[] iterables) {
658658
}
659659
}
660660

661-
public zip_longest([ParamDictionary]IDictionary<object, object> paramDict, params object[] iterables) {
661+
public zip_longest([ParamDictionary] IDictionary<object, object> paramDict, params object[] iterables) {
662662
object fill;
663663

664664
if (paramDict.TryGetValue("fillvalue", out fill)) {
@@ -747,7 +747,7 @@ public product(CodeContext context, params object[] iterables) {
747747
InnerEnumerator = Yielder(ArrayUtils.ConvertAll(iterables, x => new PythonList(context, PythonOps.GetEnumerator(x))));
748748
}
749749

750-
public product(CodeContext context, [ParamDictionary]IDictionary<object, object> paramDict, params object[] iterables) {
750+
public product(CodeContext context, [ParamDictionary] IDictionary<object, object> paramDict, params object[] iterables) {
751751
object repeat;
752752
int iRepeat = 1;
753753
if (paramDict.TryGetValue("repeat", out repeat)) {
@@ -970,7 +970,7 @@ public permutations(CodeContext context, object iterable) {
970970

971971
public permutations(CodeContext context, object iterable, object r) {
972972
_data = new PythonList(context, iterable);
973-
973+
974974
InnerEnumerator = Yielder(GetR(r, _data));
975975
}
976976

@@ -1133,9 +1133,9 @@ IEnumerator IEnumerable.GetEnumerator() {
11331133

11341134
#endregion
11351135
}
1136-
1136+
11371137
[PythonType]
1138-
public class starmap : IterBase {
1138+
public class starmap : IterBase {
11391139
public starmap(CodeContext context, object function, object iterable) {
11401140
InnerEnumerator = Yielder(context, function, PythonOps.GetEnumerator(iterable));
11411141
}
@@ -1194,7 +1194,7 @@ public void __setstate__(object state) {
11941194

11951195
private IEnumerator<object> Yielder(object predicate, IEnumerator iter) {
11961196
while (MoveNextHelper(iter)) {
1197-
if(!Converter.ConvertToBoolean(
1197+
if (!Converter.ConvertToBoolean(
11981198
_context.LanguageContext.CallSplat(predicate, iter.Current)
11991199
)) {
12001200
break;

Src/IronPython.Modules/ModuleOps.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010
using System.Numerics;
1111
using System.Runtime.InteropServices;
1212

13-
using Microsoft.Scripting;
14-
using Microsoft.Scripting.Utils;
15-
1613
using IronPython.Runtime;
1714
using IronPython.Runtime.Exceptions;
1815
using IronPython.Runtime.Operations;
1916
using IronPython.Runtime.Types;
2017

18+
using Microsoft.Scripting.Utils;
19+
2120
namespace IronPython.Modules {
2221
/// <summary>
2322
/// Provides helper functions which need to be called from generated code to implement various
@@ -92,7 +91,7 @@ public static CTypes.CData CheckSimpleCDataType(object o, object type) {
9291
bool valid = true;
9392
// if we have an array, we can also send a pointer as long as the element types
9493
// for the pointer and array are the same
95-
if(res != null && res.NativeType is CTypes.ArrayType at) {
94+
if (res != null && res.NativeType is CTypes.ArrayType at) {
9695
valid = ((type is CTypes.ArrayType t) && (t.ElementType == at.ElementType)) ||
9796
((type is CTypes.PointerType p) && (p._type == at.ElementType));
9897
}
@@ -109,7 +108,7 @@ public static CTypes.CData CheckSimpleCDataType(object o, object type) {
109108
if (res == null && PythonOps.TryGetBoundAttr(o, "_as_parameter_", out object asParam)) {
110109
res = asParam as CTypes._CFuncPtr;
111110
}
112-
111+
113112
if (res == null || res.NativeType != type) {
114113
throw ArgumentError(type, ((PythonType)type).Name, o);
115114
}
@@ -297,14 +296,14 @@ public static IntPtr GetPointer(object value) {
297296
}
298297

299298
if (value is int iVal) {
300-
if(iVal > int.MaxValue) {
299+
if (iVal > int.MaxValue) {
301300
iVal = -1;
302301
}
303302
return new IntPtr(iVal);
304303
}
305304

306305
if (value is BigInteger bigVal) {
307-
if(bigVal > long.MaxValue) {
306+
if (bigVal > long.MaxValue) {
308307
bigVal = -1;
309308
}
310309
return new IntPtr((long)bigVal);

Src/IronPython.Modules/NtSignalState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ internal static class NativeSignal {
102102

103103
[DllImport("Kernel32")]
104104
[return: MarshalAs(UnmanagedType.Bool)]
105-
internal static extern bool SetConsoleCtrlHandler(WinSignalsHandler Handler, [MarshalAs(UnmanagedType.Bool)]bool Add);
105+
internal static extern bool SetConsoleCtrlHandler(WinSignalsHandler Handler, [MarshalAs(UnmanagedType.Bool)] bool Add);
106106

107107
[DllImport("Kernel32")]
108108
[return: MarshalAs(UnmanagedType.Bool)]

Src/IronPython.Modules/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
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
using System.Reflection;
5-
using System.Runtime.CompilerServices;
65
using System.Runtime.InteropServices;
76
using System.Security;
87

Src/IronPython.Modules/ResourceMetaPathImporter.cs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
using System.IO;
44
using System.Linq;
55
using System.Reflection;
6+
67
using IronPython.Runtime;
78
using IronPython.Runtime.Exceptions;
89
using IronPython.Zlib;
10+
911
using Microsoft.Scripting;
1012
using Microsoft.Scripting.Runtime;
1113

@@ -131,8 +133,7 @@ public object load_module(CodeContext /*!*/ context, string fullname) {
131133
modules.Add(fullname, mod);
132134
try {
133135
script.Run(mod.Scope);
134-
}
135-
catch (Exception) {
136+
} catch (Exception) {
136137
modules.Remove(fullname);
137138
throw;
138139
}
@@ -175,8 +176,7 @@ private byte[] GetCodeFromData(CodeContext /*!*/ context, bool isbytecode, Packe
175176
if (data != null) {
176177
if (isbytecode) {
177178
// would put in code to unmarshal the bytecode here...
178-
}
179-
else {
179+
} else {
180180
code = data;
181181
}
182182
}
@@ -221,8 +221,8 @@ public static PackedResourceInfo Create(string fullName, int compress,
221221
#if DEBUG
222222
public override string ToString() {
223223
var sizeDesc = String.Format("{0} bytes", _fileSize);
224-
if (Convert.ToDouble(_fileSize)/1024.0 > 1.0)
225-
sizeDesc = String.Format("{0} KB", Math.Round(Convert.ToDouble(_fileSize)/1024.0, 1));
224+
if (Convert.ToDouble(_fileSize) / 1024.0 > 1.0)
225+
sizeDesc = String.Format("{0} KB", Math.Round(Convert.ToDouble(_fileSize) / 1024.0, 1));
226226
return String.Format("{0} ({1})", FullName, sizeDesc);
227227
}
228228
#endif
@@ -259,26 +259,25 @@ where isPyFile
259259
let path = lineage.Take(lineage.Length - 1).ToArray()
260260
orderby fileName
261261
select new {
262-
name = fileName,
263-
path,
264-
dottedPath = String.Join(".", path),
265-
entry
266-
};
262+
name = fileName,
263+
path,
264+
dottedPath = String.Join(".", path),
265+
entry
266+
};
267267
var moduleContents =
268268
from source in parsedSources
269269
orderby source.dottedPath
270270
group source by source.dottedPath
271271
into moduleGroup
272272
select new {
273-
moduleGroup.Key,
274-
Items = moduleGroup.Select(item => item.entry).ToArray()
275-
};
273+
moduleGroup.Key,
274+
Items = moduleGroup.Select(item => item.entry).ToArray()
275+
};
276276
modules = moduleContents.ToDictionary(
277277
moduleGroup => moduleGroup.Key,
278278
moduleGroup => moduleGroup.Items);
279279
return true;
280-
}
281-
catch (Exception exception) {
280+
} catch (Exception exception) {
282281
files = null;
283282
modules = null;
284283
unpackingError = String.Format("{0}: {1}", exception.GetType().Name, exception.Message);
@@ -310,7 +309,7 @@ private bool ReadZipDirectory(out IDictionary<string, PackedResourceInfo> result
310309
var endofCentralDir = new byte[22];
311310

312311
reader.BaseStream.Seek(-22, SeekOrigin.End);
313-
var headerPosition = (int) reader.BaseStream.Position;
312+
var headerPosition = (int)reader.BaseStream.Position;
314313
if (reader.Read(endofCentralDir, 0, 22) != 22) {
315314
unpackingError = "Can't read ZIP resource: Invalid ZIP Directory.";
316315
return false;
@@ -332,8 +331,7 @@ private bool ReadZipDirectory(out IDictionary<string, PackedResourceInfo> result
332331
.ToDictionary(entry => entry.FullName);
333332
return true;
334333
}
335-
}
336-
catch (Exception exception) {
334+
} catch (Exception exception) {
337335
unpackingError = String.Format("{0}: {1}", exception.GetType().Name, exception.Message);
338336
return false;
339337
}
@@ -410,21 +408,19 @@ public bool GetData(PackedResourceInfo tocEntry, out byte[] result, out string u
410408
byte[] rawData;
411409
try {
412410
rawData = reader.ReadBytes(compress == 0 ? dataSize : dataSize + 1);
413-
}
414-
catch {
411+
} catch {
415412
unpackingError = "Can't read data";
416413
return false;
417414
}
418415

419416
if (compress != 0) {
420-
rawData[dataSize] = (byte) 'Z';
417+
rawData[dataSize] = (byte)'Z';
421418
}
422419

423420
result = compress == 0 ? rawData : ZlibModule.Decompress(rawData, -15);
424421
return true;
425422
}
426-
}
427-
catch (Exception exception) {
423+
} catch (Exception exception) {
428424
unpackingError = String.Format("{0}: {1}", exception.GetType().Name, exception.Message);
429425
return false;
430426
}

Src/IronPython.Modules/SimpleSignalState.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
2+
53
using IronPython.Runtime;
64

75
#if FEATURE_PROCESS
@@ -16,7 +14,7 @@ public SimpleSignalState(PythonContext pc)
1614

1715
private void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e) {
1816
int pySignal;
19-
switch(e.SpecialKey) {
17+
switch (e.SpecialKey) {
2018
case ConsoleSpecialKey.ControlC:
2119
pySignal = SIGINT;
2220
break;
@@ -28,7 +26,7 @@ private void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e) {
2826
default:
2927
throw new InvalidOperationException("unreachable");
3028
}
31-
29+
3230
lock (PySignalToPyHandler) {
3331
if (PySignalToPyHandler[pySignal].GetType() == typeof(int)) {
3432
int tempId = (int)PySignalToPyHandler[pySignal];

0 commit comments

Comments
 (0)