Skip to content

Commit f2f58a2

Browse files
committed
Remove unnecessary NotNone attributes
1 parent aa20681 commit f2f58a2

30 files changed

+262
-261
lines changed

src/core/IronPython.Modules/ResourceMetaPathImporter.cs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information.
4+
15
using System;
26
using System.Collections.Generic;
37
using System.IO;
48
using System.Linq;
59
using System.Reflection;
10+
611
using IronPython.Runtime;
712
using IronPython.Runtime.Exceptions;
813
using IronPython.Zlib;
14+
915
using Microsoft.Scripting;
1016
using Microsoft.Scripting.Runtime;
1117

@@ -131,8 +137,7 @@ public object load_module(CodeContext /*!*/ context, string fullname) {
131137
modules.Add(fullname, mod);
132138
try {
133139
script.Run(mod.Scope);
134-
}
135-
catch (Exception) {
140+
} catch (Exception) {
136141
modules.Remove(fullname);
137142
throw;
138143
}
@@ -175,8 +180,7 @@ private byte[] GetCodeFromData(CodeContext /*!*/ context, bool isbytecode, Packe
175180
if (data != null) {
176181
if (isbytecode) {
177182
// would put in code to unmarshal the bytecode here...
178-
}
179-
else {
183+
} else {
180184
code = data;
181185
}
182186
}
@@ -221,8 +225,8 @@ public static PackedResourceInfo Create(string fullName, int compress,
221225
#if DEBUG
222226
public override string ToString() {
223227
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));
228+
if (Convert.ToDouble(_fileSize) / 1024.0 > 1.0)
229+
sizeDesc = String.Format("{0} KB", Math.Round(Convert.ToDouble(_fileSize) / 1024.0, 1));
226230
return String.Format("{0} ({1})", FullName, sizeDesc);
227231
}
228232
#endif
@@ -259,26 +263,25 @@ where isPyFile
259263
let path = lineage.Take(lineage.Length - 1).ToArray()
260264
orderby fileName
261265
select new {
262-
name = fileName,
263-
path,
264-
dottedPath = String.Join(".", path),
265-
entry
266-
};
266+
name = fileName,
267+
path,
268+
dottedPath = String.Join(".", path),
269+
entry
270+
};
267271
var moduleContents =
268272
from source in parsedSources
269273
orderby source.dottedPath
270274
group source by source.dottedPath
271275
into moduleGroup
272276
select new {
273-
moduleGroup.Key,
274-
Items = moduleGroup.Select(item => item.entry).ToArray()
275-
};
277+
moduleGroup.Key,
278+
Items = moduleGroup.Select(item => item.entry).ToArray()
279+
};
276280
modules = moduleContents.ToDictionary(
277281
moduleGroup => moduleGroup.Key,
278282
moduleGroup => moduleGroup.Items);
279283
return true;
280-
}
281-
catch (Exception exception) {
284+
} catch (Exception exception) {
282285
files = null;
283286
modules = null;
284287
unpackingError = String.Format("{0}: {1}", exception.GetType().Name, exception.Message);
@@ -310,7 +313,7 @@ private bool ReadZipDirectory(out IDictionary<string, PackedResourceInfo> result
310313
var endofCentralDir = new byte[22];
311314

312315
reader.BaseStream.Seek(-22, SeekOrigin.End);
313-
var headerPosition = (int) reader.BaseStream.Position;
316+
var headerPosition = (int)reader.BaseStream.Position;
314317
if (reader.Read(endofCentralDir, 0, 22) != 22) {
315318
unpackingError = "Can't read ZIP resource: Invalid ZIP Directory.";
316319
return false;
@@ -332,8 +335,7 @@ private bool ReadZipDirectory(out IDictionary<string, PackedResourceInfo> result
332335
.ToDictionary(entry => entry.FullName);
333336
return true;
334337
}
335-
}
336-
catch (Exception exception) {
338+
} catch (Exception exception) {
337339
unpackingError = String.Format("{0}: {1}", exception.GetType().Name, exception.Message);
338340
return false;
339341
}
@@ -410,26 +412,23 @@ public bool GetData(PackedResourceInfo tocEntry, out byte[] result, out string u
410412
byte[] rawData;
411413
try {
412414
rawData = reader.ReadBytes(compress == 0 ? dataSize : dataSize + 1);
413-
}
414-
catch {
415+
} catch {
415416
unpackingError = "Can't read data";
416417
return false;
417418
}
418419

419420
if (compress != 0) {
420-
rawData[dataSize] = (byte) 'Z';
421+
rawData[dataSize] = (byte)'Z';
421422
}
422423

423424
result = compress == 0 ? rawData : ZlibModule.Decompress(rawData, -15);
424425
return true;
425426
}
426-
}
427-
catch (Exception exception) {
427+
} catch (Exception exception) {
428428
unpackingError = String.Format("{0}: {1}", exception.GetType().Name, exception.Message);
429429
return false;
430430
}
431431
}
432432
}
433-
434433
}
435434
}

src/core/IronPython.Modules/_collections.cs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@
1010
using System.Runtime.CompilerServices;
1111
using System.Text;
1212

13-
using Microsoft.Scripting;
14-
using Microsoft.Scripting.Actions;
15-
using Microsoft.Scripting.Runtime;
16-
using Microsoft.Scripting.Utils;
17-
1813
using IronPython.Runtime;
1914
using IronPython.Runtime.Binding;
20-
using IronPython.Runtime.Exceptions;
2115
using IronPython.Runtime.Operations;
2216
using IronPython.Runtime.Types;
2317

18+
using Microsoft.Scripting;
19+
using Microsoft.Scripting.Actions;
20+
using Microsoft.Scripting.Runtime;
21+
using Microsoft.Scripting.Utils;
22+
2423
[assembly: PythonModule("_collections", typeof(IronPython.Modules.PythonCollections))]
2524
namespace IronPython.Modules {
2625
public class PythonCollections {
@@ -42,7 +41,7 @@ private deque(int maxlen) {
4241
_data = _maxLen < 0 ? new object[8] : new object[Math.Min(_maxLen, 8)];
4342
}
4443

45-
public static object __new__(CodeContext/*!*/ context, PythonType cls, [ParamDictionary]IDictionary<object, object> dict, params object[] args) {
44+
public static object __new__(CodeContext/*!*/ context, PythonType cls, [ParamDictionary] IDictionary<object, object> dict, params object[] args) {
4645
if (cls == DynamicHelpers.GetPythonTypeFromType(typeof(deque))) return new deque();
4746
return cls.CreateInstance(context);
4847
}
@@ -52,7 +51,7 @@ public void __init__() {
5251
clear();
5352
}
5453

55-
public void __init__([ParamDictionary]IDictionary<object, object> dict) {
54+
public void __init__([ParamDictionary] IDictionary<object, object> dict) {
5655
_maxLen = VerifyMaxLen(dict);
5756
clear();
5857
}
@@ -65,12 +64,12 @@ public void __init__(object iterable) {
6564

6665
public void __init__(object iterable, object maxlen) {
6766
_maxLen = VerifyMaxLenValue(maxlen);
68-
67+
6968
clear();
7069
extend(iterable);
7170
}
7271

73-
public void __init__(object iterable, [ParamDictionary]IDictionary<object, object> dict) {
72+
public void __init__(object iterable, [ParamDictionary] IDictionary<object, object> dict) {
7473
if (VerifyMaxLen(dict) < 0) {
7574
__init__(iterable);
7675
} else {
@@ -82,7 +81,7 @@ private static int VerifyMaxLen(IDictionary<object, object> dict) {
8281
if (dict.Count != 1) {
8382
throw PythonOps.TypeError("deque() takes at most 1 keyword argument ({0} given)", dict.Count);
8483
}
85-
84+
8685
object value;
8786
if (!dict.TryGetValue("maxlen", out value)) {
8887
IEnumerator<object> e = dict.Keys.GetEnumerator();
@@ -105,7 +104,7 @@ private static int VerifyMaxLenValue(object value) {
105104
Extensible<BigInteger> ebi => (int)ebi.Value,
106105
_ => throw PythonOps.TypeError("an integer is required")
107106
};
108-
107+
109108
if (res < 0) throw PythonOps.ValueError("maxlen must be non-negative");
110109

111110
return res;
@@ -425,7 +424,7 @@ public void rotate(CodeContext/*!*/ context, object n) {
425424
// too bad, we got gaps, looks like we'll be doing some real work.
426425
object[] newData = new object[_itemCnt]; // we re-size to itemCnt so that future rotates don't require work
427426
int curWriteIndex = rot;
428-
WalkDeque(delegate(int curIndex) {
427+
WalkDeque(delegate (int curIndex) {
429428
newData[curWriteIndex] = _data[curIndex];
430429
curWriteIndex = (curWriteIndex + 1) % _itemCnt;
431430
return true;
@@ -534,7 +533,7 @@ public void __delitem__(CodeContext/*!*/ context, object index) {
534533
// we'll just recreate our data by walking the data once.
535534
object[] newData = new object[_data.Length];
536535
int writeIndex = 0;
537-
WalkDeque(delegate(int curIndex) {
536+
WalkDeque(delegate (int curIndex) {
538537
if (curIndex != realIndex) {
539538
newData[writeIndex++] = _data[curIndex];
540539
}
@@ -925,7 +924,7 @@ private bool WalkDeque(DequeWalker walker) {
925924
string comma = "";
926925

927926
lock (_lockObj) {
928-
WalkDeque(delegate(int index) {
927+
WalkDeque(delegate (int index) {
929928
sb.Append(comma);
930929
sb.Append(PythonOps.Repr(context, _data[index]));
931930
comma = ", ";
@@ -1149,18 +1148,18 @@ public defaultdict(CodeContext/*!*/ context) {
11491148
this.default_factory = default_factory;
11501149
}
11511150

1152-
public void __init__(CodeContext/*!*/ context, object default_factory, [NotNone] params object[] args) {
1151+
public void __init__(CodeContext/*!*/ context, object default_factory, params object[] args) {
11531152
__init__(context, default_factory);
11541153

11551154
foreach (object o in args) {
11561155
update(context, o);
11571156
}
11581157
}
11591158

1160-
public void __init__(CodeContext/*!*/ context, object default_factory, [ParamDictionary, NotNone] IDictionary<object, object> dict, [NotNone] params object[] args) {
1159+
public void __init__(CodeContext/*!*/ context, object default_factory, [ParamDictionary] IDictionary<object, object> dict, params object[] args) {
11611160
__init__(context, default_factory, args);
11621161

1163-
foreach (KeyValuePair<object , object> kvp in dict) {
1162+
foreach (KeyValuePair<object, object> kvp in dict) {
11641163
this[kvp.Key] = kvp.Value;
11651164
}
11661165
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
using System.Collections.Generic;
88

9-
using Microsoft.Scripting;
10-
119
using IronPython.Runtime;
1210
using IronPython.Runtime.Operations;
1311
using IronPython.Runtime.Types;
1412

13+
using Microsoft.Scripting;
14+
1515
namespace IronPython.Modules {
1616
/// <summary>
1717
/// Provides support for interop with native code from Python code.
@@ -44,7 +44,7 @@ protected _Structure() {
4444
MemHolder = new MemoryHolder(NativeType.Size);
4545
}
4646

47-
public void __init__([NotNone] params object[] args) {
47+
public void __init__(params object[] args) {
4848
CheckAbstract();
4949

5050
INativeType nativeType = NativeType;
@@ -53,7 +53,7 @@ public void __init__([NotNone] params object[] args) {
5353
st.SetValueInternal(MemHolder, 0, args);
5454
}
5555

56-
public void __init__(CodeContext/*!*/ context, [ParamDictionary]IDictionary<string, object> kwargs) {
56+
public void __init__(CodeContext/*!*/ context, [ParamDictionary] IDictionary<string, object> kwargs) {
5757
CheckAbstract();
5858

5959
foreach (var x in kwargs) {
@@ -72,6 +72,6 @@ private void CheckAbstract() {
7272
}
7373
}
7474
}
75-
7675
}
76+
7777
#endif

src/core/IronPython.Modules/_datetime.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ public object replace() {
467467
}
468468

469469
// instance methods
470-
public virtual date replace(CodeContext/*!*/ context, [NotNone, ParamDictionary] IDictionary<object, object> dict) {
470+
public virtual date replace(CodeContext/*!*/ context, [ParamDictionary] IDictionary<object, object> dict) {
471471
int year2 = _dateTime.Year;
472472
int month2 = _dateTime.Month;
473473
int day2 = _dateTime.Day;
@@ -679,7 +679,7 @@ public datetime(DateTime dt, tzinfo? tzinfo)
679679
}
680680

681681
// just present to match CPython's error messages...
682-
public datetime([NotNone] params object[] args) {
682+
public datetime(params object[] args) {
683683
if (args.Length < 3) {
684684
throw PythonOps.TypeError("function takes at least 3 arguments ({0} given)", args.Length);
685685
} else if (args.Length > 8) {
@@ -862,7 +862,7 @@ public object timetz() {
862862
}
863863

864864
[Documentation("gets a new datetime object with the fields provided as keyword arguments replaced.")]
865-
public override date replace(CodeContext/*!*/ context, [NotNone, ParamDictionary] IDictionary<object, object> dict) {
865+
public override date replace(CodeContext/*!*/ context, [ParamDictionary] IDictionary<object, object> dict) {
866866
int lyear = year;
867867
int lmonth = month;
868868
int lday = day;
@@ -1037,8 +1037,7 @@ public override string strftime(CodeContext/*!*/ context, [NotNone] string dateF
10371037
public double timestamp() {
10381038
if (tzinfo is null) {
10391039
return PythonTime.TicksToTimestamp(_dateTime.ToUniversalTime().Ticks);
1040-
}
1041-
else {
1040+
} else {
10421041
return (this - new datetime(new DateTime(1970, 1, 1), timezone.utc)).total_seconds();
10431042
}
10441043
}
@@ -1233,7 +1232,7 @@ public object replace() {
12331232
return this;
12341233
}
12351234

1236-
public object replace([ParamDictionary, NotNone] IDictionary<object, object> dict) {
1235+
public object replace([ParamDictionary] IDictionary<object, object> dict) {
12371236
int lhour = hour;
12381237
int lminute = minute;
12391238
int lsecond = second;
@@ -1448,10 +1447,10 @@ public class tzinfo {
14481447
public tzinfo() {
14491448
}
14501449

1451-
public tzinfo([NotNone] params object?[] args) {
1450+
public tzinfo(params object?[] args) {
14521451
}
14531452

1454-
public tzinfo([ParamDictionary, NotNone] PythonDictionary dict, [NotNone] params object?[] args) {
1453+
public tzinfo([ParamDictionary] PythonDictionary dict, params object?[] args) {
14551454
}
14561455

14571456
public virtual object fromutc([NotNone] datetime dt) {

0 commit comments

Comments
 (0)