Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 76857c0

Browse files
committed
Add formatting and linting for C# files
1 parent 563e369 commit 76857c0

File tree

117 files changed

+929
-752
lines changed

Some content is hidden

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

117 files changed

+929
-752
lines changed

.github/workflows/lint.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Linting
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
jobs:
10+
lint-dotnet:
11+
name: Lint .NET
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 15
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v2
18+
19+
- name: Setup .NET
20+
uses: actions/setup-dotnet@v1
21+
with:
22+
dotnet-version: '7.0.x'
23+
24+
- name: Lint
25+
run: dotnet format -v diag --verify-no-changes --report=format.json
26+
27+
- uses: actions/upload-artifact@v4
28+
with:
29+
name: format-report
30+
path: format.json

src/console/pythonconsole.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Reflection;
5+
56
using Python.Runtime;
67

78
namespace Python.Runtime

src/embed_tests/CodecGroups.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ namespace Python.EmbeddingTest
22
{
33
using System;
44
using System.Linq;
5+
56
using NUnit.Framework;
7+
68
using Python.Runtime;
79
using Python.Runtime.Codecs;
810

@@ -20,7 +22,7 @@ public void GetEncodersByType()
2022
};
2123

2224
var got = group.GetEncoders(typeof(Uri)).ToArray();
23-
CollectionAssert.AreEqual(new[]{encoder1, encoder2}, got);
25+
CollectionAssert.AreEqual(new[] { encoder1, encoder2 }, got);
2426
}
2527

2628
[Test]

src/embed_tests/Codecs.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
namespace Python.EmbeddingTest {
1+
namespace Python.EmbeddingTest
2+
{
23
using System;
34
using System.Collections.Generic;
45
using System.Linq;
6+
57
using NUnit.Framework;
8+
69
using Python.Runtime;
710
using Python.Runtime.Codecs;
811

@@ -169,7 +172,8 @@ public void SequenceDecoderTest()
169172
ICollection<string> stringCollection = null;
170173
Assert.DoesNotThrow(() => { codec.TryDecode(pyList, out stringCollection); });
171174
Assert.AreEqual(3, stringCollection.Count());
172-
Assert.Throws(typeof(InvalidCastException), () => {
175+
Assert.Throws(typeof(InvalidCastException), () =>
176+
{
173177
string[] array = new string[3];
174178
stringCollection.CopyTo(array, 0);
175179
});
@@ -206,7 +210,8 @@ public void SequenceDecoderTest()
206210
ICollection<string> stringCollection2 = null;
207211
Assert.DoesNotThrow(() => { codec.TryDecode(pyTuple, out stringCollection2); });
208212
Assert.AreEqual(3, stringCollection2.Count());
209-
Assert.Throws(typeof(InvalidCastException), () => {
213+
Assert.Throws(typeof(InvalidCastException), () =>
214+
{
210215
string[] array = new string[3];
211216
stringCollection2.CopyTo(array, 0);
212217
});
@@ -255,13 +260,15 @@ public void IterableDecoderTest()
255260
IEnumerable<string> stringEnumerable = null;
256261
Assert.DoesNotThrow(() => { codec.TryDecode(pyList, out stringEnumerable); });
257262

258-
Assert.Throws(typeof(InvalidCastException), () => {
263+
Assert.Throws(typeof(InvalidCastException), () =>
264+
{
259265
foreach (string item in stringEnumerable)
260266
{
261267
var x = item;
262268
}
263269
});
264-
Assert.Throws(typeof(InvalidCastException), () => {
270+
Assert.Throws(typeof(InvalidCastException), () =>
271+
{
265272
stringEnumerable.Count();
266273
});
267274

@@ -390,7 +397,7 @@ public void ExceptionDecodedNoInstance()
390397
}
391398
}
392399

393-
public static void AcceptsDateTime(DateTime v) {}
400+
public static void AcceptsDateTime(DateTime v) { }
394401

395402
[Test]
396403
public void As_Object_AffectedByDecoders()

src/embed_tests/GlobalTestsSetup.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using NUnit.Framework;
2+
23
using Python.Runtime;
34

45
namespace Python.EmbeddingTest

src/embed_tests/Inheritance.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ public class PropertyAccessorBase
206206
public virtual string VirtualProp { get; set; }
207207
}
208208

209-
public class PropertyAccessorIntermediate: PropertyAccessorBase { }
209+
public class PropertyAccessorIntermediate : PropertyAccessorBase { }
210210

211-
public class PropertyAccessorDerived: PropertyAccessorIntermediate
211+
public class PropertyAccessorDerived : PropertyAccessorIntermediate
212212
{
213213
public override string VirtualProp { set => base.VirtualProp = value.ToUpperInvariant(); }
214214
}
@@ -217,7 +217,7 @@ public class ContainerClass
217217
{
218218
public void BaseMethod() { }
219219

220-
public class InnerClass: ContainerClass
220+
public class InnerClass : ContainerClass
221221
{
222222

223223
}

src/embed_tests/Modules.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Threading;
3+
34
using NUnit.Framework;
5+
46
using Python.Runtime;
57

68
namespace Python.EmbeddingTest
@@ -385,8 +387,8 @@ public void TestThread()
385387
//add function to the scope
386388
//can be call many times, more efficient than ast
387389
ps.Exec(
388-
"import threading\n"+
389-
"lock = threading.Lock()\n"+
390+
"import threading\n" +
391+
"lock = threading.Lock()\n" +
390392
"def update():\n" +
391393
" global res, th_cnt\n" +
392394
" with lock:\n" +

src/embed_tests/NumPyTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void VarArg()
6868
{
6969
dynamic zX = np.array(new[,] { { 1, 2, 3 }, { 4, 5, 6 }, { 8, 9, 0 } });
7070
dynamic grad = np.gradient(zX, 4.0, 5.0);
71-
dynamic grad2 = np.InvokeMethod("gradient", new PyObject[] {zX, new PyFloat(4.0), new PyFloat(5.0)});
71+
dynamic grad2 = np.InvokeMethod("gradient", new PyObject[] { zX, new PyFloat(4.0), new PyFloat(5.0) });
7272

7373
Assert.AreEqual(4.125, grad[0].sum().__float__().As<double>(), 0.001);
7474
Assert.AreEqual(-1.2, grad[1].sum().__float__().As<double>(), 0.001);

src/embed_tests/References.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace Python.EmbeddingTest
22
{
33
using NUnit.Framework;
4+
45
using Python.Runtime;
56

67
public class References

src/embed_tests/TestCallbacks.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
11
using System;
22

33
using NUnit.Framework;
4+
45
using Python.Runtime;
56

6-
namespace Python.EmbeddingTest {
7-
public class TestCallbacks {
7+
namespace Python.EmbeddingTest
8+
{
9+
public class TestCallbacks
10+
{
811
[OneTimeSetUp]
9-
public void SetUp() {
12+
public void SetUp()
13+
{
1014
PythonEngine.Initialize();
1115
}
1216

1317
[OneTimeTearDown]
14-
public void Dispose() {
18+
public void Dispose()
19+
{
1520
PythonEngine.Shutdown();
1621
}
1722

1823
[Test]
19-
public void TestNoOverloadException() {
24+
public void TestNoOverloadException()
25+
{
2026
int passed = 0;
2127
var aFunctionThatCallsIntoPython = new Action<int>(value => passed = value);
22-
using (Py.GIL()) {
28+
using (Py.GIL())
29+
{
2330
using dynamic callWith42 = PythonEngine.Eval("lambda f: f([42])");
2431
using var pyFunc = aFunctionThatCallsIntoPython.ToPython();
25-
var error = Assert.Throws<PythonException>(() => callWith42(pyFunc));
32+
var error = Assert.Throws<PythonException>(() => callWith42(pyFunc));
2633
Assert.AreEqual("TypeError", error.Type.Name);
2734
string expectedArgTypes = "(<class 'list'>)";
2835
StringAssert.EndsWith(expectedArgTypes, error.Message);

src/embed_tests/TestConverter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void TestConvertSingleToManaged(
4646
var converted = Converter.ToManaged(pyFloat, typeof(float), out convertedValue, false);
4747

4848
Assert.IsTrue(converted);
49-
Assert.IsTrue(((float) convertedValue).Equals(testValue));
49+
Assert.IsTrue(((float)convertedValue).Equals(testValue));
5050
}
5151

5252
[Test]
@@ -60,7 +60,7 @@ public void TestConvertDoubleToManaged(
6060
var converted = Converter.ToManaged(pyFloat, typeof(double), out convertedValue, false);
6161

6262
Assert.IsTrue(converted);
63-
Assert.IsTrue(((double) convertedValue).Equals(testValue));
63+
Assert.IsTrue(((double)convertedValue).Equals(testValue));
6464
}
6565

6666
[Test]
@@ -164,7 +164,7 @@ public void ToPyList()
164164
[Test]
165165
public void RawListProxy()
166166
{
167-
var list = new List<string> {"hello", "world"};
167+
var list = new List<string> { "hello", "world" };
168168
var listProxy = PyObject.FromManagedObject(list);
169169
var clrObject = (CLRObject)ManagedType.GetManagedObject(listProxy);
170170
Assert.AreSame(list, clrObject.inst);

src/embed_tests/TestCustomMarshal.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
23
using NUnit.Framework;
4+
35
using Python.Runtime;
46

57
namespace Python.EmbeddingTest

src/embed_tests/TestDomainReload.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
using System.Diagnostics;
44
using System.Reflection;
55
using System.Runtime.InteropServices;
6+
67
using NUnit.Framework;
8+
79
using Python.Runtime;
810

911
using PyRuntime = Python.Runtime.Runtime;

src/embed_tests/TestFinalizer.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
using NUnit.Framework;
2-
using Python.Runtime;
31
using System;
42
using System.Collections.Generic;
53
using System.Diagnostics;
64
using System.Linq;
75
using System.Runtime.CompilerServices;
86
using System.Threading;
97

8+
using NUnit.Framework;
9+
10+
using Python.Runtime;
11+
1012
namespace Python.EmbeddingTest
1113
{
1214
public class TestFinalizer
@@ -237,7 +239,7 @@ private static IntPtr CreateStringGarbage()
237239
PyString s1 = new PyString("test_string");
238240
// s2 steal a reference from s1
239241
IntPtr address = s1.Reference.DangerousGetAddress();
240-
PyString s2 = new (StolenReference.DangerousFromPointer(address));
242+
PyString s2 = new(StolenReference.DangerousFromPointer(address));
241243
return address;
242244
}
243245
}

src/embed_tests/TestGILState.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace Python.EmbeddingTest
22
{
33
using NUnit.Framework;
4+
45
using Python.Runtime;
56

67
public class TestGILState
@@ -13,7 +14,7 @@ public void CanDisposeMultipleTimes()
1314
{
1415
using (var gilState = Py.GIL())
1516
{
16-
for(int i = 0; i < 50; i++)
17+
for (int i = 0; i < 50; i++)
1718
gilState.Dispose();
1819
}
1920
}

src/embed_tests/TestInstanceWrapping.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Globalization;
3+
34
using NUnit.Framework;
5+
46
using Python.Runtime;
57

68
namespace Python.EmbeddingTest
@@ -44,10 +46,10 @@ public void WeakRefIsNone_AfterObjectIsGone()
4446
Assert.IsTrue(weakref.Invoke().IsNone());
4547
}
4648

47-
class Base {}
48-
class Derived: Base { }
49+
class Base { }
50+
class Derived : Base { }
4951

50-
class Overloaded: Derived
52+
class Overloaded : Derived
5153
{
5254
public int Value { get; set; }
5355
public void IntOrStr(int arg) => this.Value = arg;

src/embed_tests/TestNamedArguments.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
23
using NUnit.Framework;
4+
35
using Python.Runtime;
46

57
namespace Python.EmbeddingTest

src/embed_tests/TestOperator.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
using System;
2+
using System.Linq;
3+
using System.Reflection;
4+
15
using NUnit.Framework;
26

37
using Python.Runtime;
48
using Python.Runtime.Codecs;
59

6-
using System;
7-
using System.Linq;
8-
using System.Reflection;
9-
1010
namespace Python.EmbeddingTest
1111
{
1212
public class TestOperator
@@ -541,12 +541,12 @@ public void ForwardOperatorOverloads()
541541
[Test]
542542
public void TupleComparisonOperatorOverloads()
543543
{
544-
TupleCodec<ValueTuple>.Register();
545-
string name = string.Format("{0}.{1}",
546-
typeof(OperableObject).DeclaringType.Name,
547-
typeof(OperableObject).Name);
544+
TupleCodec<ValueTuple>.Register();
545+
string name = string.Format("{0}.{1}",
546+
typeof(OperableObject).DeclaringType.Name,
547+
typeof(OperableObject).Name);
548548
string module = MethodBase.GetCurrentMethod().DeclaringType.Namespace;
549-
PythonEngine.Exec($@"
549+
PythonEngine.Exec($@"
550550
from {module} import *
551551
cls = {name}
552552
a = cls(2)

0 commit comments

Comments
 (0)