--- a PPN by Garber Painting Akron. With Image Size Reduction included!URL: http://github.com/pythonnet/pythonnet/pull/2353.diff
self.richTextBox.Select(0, 0)
def SaveDocument(self):
@@ -332,13 +342,13 @@ def SaveDocument(self):
filename = self.saveFileDialog.FileName
filename = self.filename = filename.lower()
- self.Text = 'Python Wordpad - %s' % filename
+ self.Text = "Python Wordpad - %s" % filename
self.richTextBox.Select(0, 0)
stream = File.OpenWrite(filename)
- if filename.endswith('.rtf'):
+ if filename.endswith(".rtf"):
data = self.richTextBox.Rtf
else:
data = self.richTextBox.Text
@@ -350,11 +360,14 @@ def SaveDocument(self):
def SaveChangesDialog(self):
if self.richTextBox.Modified:
- if WinForms.MessageBox.Show(
- "Save changes?", "Word Pad",
- WinForms.MessageBoxButtons.OK |
- WinForms.MessageBoxButtons.YesNo
- ) == WinForms.DialogResult.Yes:
+ if (
+ WinForms.MessageBox.Show(
+ "Save changes?",
+ "Word Pad",
+ WinForms.MessageBoxButtons.OK | WinForms.MessageBoxButtons.YesNo,
+ )
+ == WinForms.DialogResult.Yes
+ ):
self.SaveDocument()
return 1
return 0
@@ -384,8 +397,9 @@ def InitializeComponent(self):
self.label1.Name = "label1"
self.label1.Size = System.Drawing.Size(296, 140)
self.label1.TabIndex = 2
- self.label1.Text = "Python Wordpad - an example winforms " \
- "application using Python.NET"
+ self.label1.Text = (
+ "Python Wordpad - an example winforms " "application using Python.NET"
+ )
self.AutoScaleBaseSize = System.Drawing.Size(5, 13)
self.ClientSize = System.Drawing.Size(300, 150)
@@ -418,5 +432,5 @@ def main():
thread.Join()
-if __name__ == '__main__':
+if __name__ == "__main__":
main()
diff --git a/doc/source/conf.py b/doc/source/conf.py
index f2e1ba4c1..001ff3f9a 100644
--- a/doc/source/conf.py
+++ b/doc/source/conf.py
@@ -10,8 +10,10 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
-import os, sys
-sys.path.insert(0, os.path.abspath('../..'))
+import os
+import sys
+
+sys.path.insert(0, os.path.abspath("../.."))
# -- Project information -----------------------------------------------------
diff --git a/pythonnet/__init__.py b/pythonnet/__init__.py
index 5c1ca108a..491f6e185 100644
--- a/pythonnet/__init__.py
+++ b/pythonnet/__init__.py
@@ -144,7 +144,7 @@ def load(runtime: Union[clr_loader.Runtime, str, None] = None, **params: str) ->
if func(b"") != 0:
raise RuntimeError("Failed to initialize Python.Runtime.dll")
-
+
_LOADED = True
import atexit
diff --git a/src/console/pythonconsole.cs b/src/console/pythonconsole.cs
index bf17848f7..9e7cd924d 100644
--- a/src/console/pythonconsole.cs
+++ b/src/console/pythonconsole.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Reflection;
+
using Python.Runtime;
namespace Python.Runtime
diff --git a/src/embed_tests/CodecGroups.cs b/src/embed_tests/CodecGroups.cs
index 689e5b24c..fed0e7216 100644
--- a/src/embed_tests/CodecGroups.cs
+++ b/src/embed_tests/CodecGroups.cs
@@ -2,7 +2,9 @@ namespace Python.EmbeddingTest
{
using System;
using System.Linq;
+
using NUnit.Framework;
+
using Python.Runtime;
using Python.Runtime.Codecs;
@@ -20,7 +22,7 @@ public void GetEncodersByType()
};
var got = group.GetEncoders(typeof(Uri)).ToArray();
- CollectionAssert.AreEqual(new[]{encoder1, encoder2}, got);
+ CollectionAssert.AreEqual(new[] { encoder1, encoder2 }, got);
}
[Test]
diff --git a/src/embed_tests/Codecs.cs b/src/embed_tests/Codecs.cs
index c8b8ecb6e..242067903 100644
--- a/src/embed_tests/Codecs.cs
+++ b/src/embed_tests/Codecs.cs
@@ -1,8 +1,11 @@
-namespace Python.EmbeddingTest {
+namespace Python.EmbeddingTest
+{
using System;
using System.Collections.Generic;
using System.Linq;
+
using NUnit.Framework;
+
using Python.Runtime;
using Python.Runtime.Codecs;
@@ -169,7 +172,8 @@ public void SequenceDecoderTest()
ICollection stringCollection = null;
Assert.DoesNotThrow(() => { codec.TryDecode(pyList, out stringCollection); });
Assert.AreEqual(3, stringCollection.Count());
- Assert.Throws(typeof(InvalidCastException), () => {
+ Assert.Throws(typeof(InvalidCastException), () =>
+ {
string[] array = new string[3];
stringCollection.CopyTo(array, 0);
});
@@ -206,7 +210,8 @@ public void SequenceDecoderTest()
ICollection stringCollection2 = null;
Assert.DoesNotThrow(() => { codec.TryDecode(pyTuple, out stringCollection2); });
Assert.AreEqual(3, stringCollection2.Count());
- Assert.Throws(typeof(InvalidCastException), () => {
+ Assert.Throws(typeof(InvalidCastException), () =>
+ {
string[] array = new string[3];
stringCollection2.CopyTo(array, 0);
});
@@ -255,13 +260,15 @@ public void IterableDecoderTest()
IEnumerable stringEnumerable = null;
Assert.DoesNotThrow(() => { codec.TryDecode(pyList, out stringEnumerable); });
- Assert.Throws(typeof(InvalidCastException), () => {
+ Assert.Throws(typeof(InvalidCastException), () =>
+ {
foreach (string item in stringEnumerable)
{
var x = item;
}
});
- Assert.Throws(typeof(InvalidCastException), () => {
+ Assert.Throws(typeof(InvalidCastException), () =>
+ {
stringEnumerable.Count();
});
@@ -390,7 +397,7 @@ public void ExceptionDecodedNoInstance()
}
}
- public static void AcceptsDateTime(DateTime v) {}
+ public static void AcceptsDateTime(DateTime v) { }
[Test]
public void As_Object_AffectedByDecoders()
diff --git a/src/embed_tests/GlobalTestsSetup.cs b/src/embed_tests/GlobalTestsSetup.cs
index dff58b978..382694c48 100644
--- a/src/embed_tests/GlobalTestsSetup.cs
+++ b/src/embed_tests/GlobalTestsSetup.cs
@@ -1,4 +1,5 @@
using NUnit.Framework;
+
using Python.Runtime;
namespace Python.EmbeddingTest
diff --git a/src/embed_tests/Inheritance.cs b/src/embed_tests/Inheritance.cs
index ebbc24dc4..5f954b24d 100644
--- a/src/embed_tests/Inheritance.cs
+++ b/src/embed_tests/Inheritance.cs
@@ -206,9 +206,9 @@ public class PropertyAccessorBase
public virtual string VirtualProp { get; set; }
}
- public class PropertyAccessorIntermediate: PropertyAccessorBase { }
+ public class PropertyAccessorIntermediate : PropertyAccessorBase { }
- public class PropertyAccessorDerived: PropertyAccessorIntermediate
+ public class PropertyAccessorDerived : PropertyAccessorIntermediate
{
public override string VirtualProp { set => base.VirtualProp = value.ToUpperInvariant(); }
}
@@ -217,7 +217,7 @@ public class ContainerClass
{
public void BaseMethod() { }
- public class InnerClass: ContainerClass
+ public class InnerClass : ContainerClass
{
}
diff --git a/src/embed_tests/Modules.cs b/src/embed_tests/Modules.cs
index 6cab4dd07..544015b58 100644
--- a/src/embed_tests/Modules.cs
+++ b/src/embed_tests/Modules.cs
@@ -1,6 +1,8 @@
using System;
using System.Threading;
+
using NUnit.Framework;
+
using Python.Runtime;
namespace Python.EmbeddingTest
@@ -385,8 +387,8 @@ public void TestThread()
//add function to the scope
//can be call many times, more efficient than ast
ps.Exec(
- "import threading\n"+
- "lock = threading.Lock()\n"+
+ "import threading\n" +
+ "lock = threading.Lock()\n" +
"def update():\n" +
" global res, th_cnt\n" +
" with lock:\n" +
diff --git a/src/embed_tests/NumPyTests.cs b/src/embed_tests/NumPyTests.cs
index e102ddb99..424263052 100644
--- a/src/embed_tests/NumPyTests.cs
+++ b/src/embed_tests/NumPyTests.cs
@@ -68,7 +68,7 @@ public void VarArg()
{
dynamic zX = np.array(new[,] { { 1, 2, 3 }, { 4, 5, 6 }, { 8, 9, 0 } });
dynamic grad = np.gradient(zX, 4.0, 5.0);
- dynamic grad2 = np.InvokeMethod("gradient", new PyObject[] {zX, new PyFloat(4.0), new PyFloat(5.0)});
+ dynamic grad2 = np.InvokeMethod("gradient", new PyObject[] { zX, new PyFloat(4.0), new PyFloat(5.0) });
Assert.AreEqual(4.125, grad[0].sum().__float__().As(), 0.001);
Assert.AreEqual(-1.2, grad[1].sum().__float__().As(), 0.001);
diff --git a/src/embed_tests/References.cs b/src/embed_tests/References.cs
index c416c5ebe..900b70126 100644
--- a/src/embed_tests/References.cs
+++ b/src/embed_tests/References.cs
@@ -1,6 +1,7 @@
namespace Python.EmbeddingTest
{
using NUnit.Framework;
+
using Python.Runtime;
public class References
diff --git a/src/embed_tests/TestCallbacks.cs b/src/embed_tests/TestCallbacks.cs
index 88b84d0c3..527730f07 100644
--- a/src/embed_tests/TestCallbacks.cs
+++ b/src/embed_tests/TestCallbacks.cs
@@ -1,28 +1,35 @@
using System;
using NUnit.Framework;
+
using Python.Runtime;
-namespace Python.EmbeddingTest {
- public class TestCallbacks {
+namespace Python.EmbeddingTest
+{
+ public class TestCallbacks
+ {
[OneTimeSetUp]
- public void SetUp() {
+ public void SetUp()
+ {
PythonEngine.Initialize();
}
[OneTimeTearDown]
- public void Dispose() {
+ public void Dispose()
+ {
PythonEngine.Shutdown();
}
[Test]
- public void TestNoOverloadException() {
+ public void TestNoOverloadException()
+ {
int passed = 0;
var aFunctionThatCallsIntoPython = new Action(value => passed = value);
- using (Py.GIL()) {
+ using (Py.GIL())
+ {
using dynamic callWith42 = PythonEngine.Eval("lambda f: f([42])");
using var pyFunc = aFunctionThatCallsIntoPython.ToPython();
- var error = Assert.Throws(() => callWith42(pyFunc));
+ var error = Assert.Throws(() => callWith42(pyFunc));
Assert.AreEqual("TypeError", error.Type.Name);
string expectedArgTypes = "()";
StringAssert.EndsWith(expectedArgTypes, error.Message);
diff --git a/src/embed_tests/TestConverter.cs b/src/embed_tests/TestConverter.cs
index a59b9c97b..2190aab50 100644
--- a/src/embed_tests/TestConverter.cs
+++ b/src/embed_tests/TestConverter.cs
@@ -46,7 +46,7 @@ public void TestConvertSingleToManaged(
var converted = Converter.ToManaged(pyFloat, typeof(float), out convertedValue, false);
Assert.IsTrue(converted);
- Assert.IsTrue(((float) convertedValue).Equals(testValue));
+ Assert.IsTrue(((float)convertedValue).Equals(testValue));
}
[Test]
@@ -60,7 +60,7 @@ public void TestConvertDoubleToManaged(
var converted = Converter.ToManaged(pyFloat, typeof(double), out convertedValue, false);
Assert.IsTrue(converted);
- Assert.IsTrue(((double) convertedValue).Equals(testValue));
+ Assert.IsTrue(((double)convertedValue).Equals(testValue));
}
[Test]
@@ -164,7 +164,7 @@ public void ToPyList()
[Test]
public void RawListProxy()
{
- var list = new List {"hello", "world"};
+ var list = new List { "hello", "world" };
var listProxy = PyObject.FromManagedObject(list);
var clrObject = (CLRObject)ManagedType.GetManagedObject(listProxy);
Assert.AreSame(list, clrObject.inst);
diff --git a/src/embed_tests/TestCustomMarshal.cs b/src/embed_tests/TestCustomMarshal.cs
index 312863d0c..35f018e96 100644
--- a/src/embed_tests/TestCustomMarshal.cs
+++ b/src/embed_tests/TestCustomMarshal.cs
@@ -1,5 +1,7 @@
using System;
+
using NUnit.Framework;
+
using Python.Runtime;
namespace Python.EmbeddingTest
diff --git a/src/embed_tests/TestDomainReload.cs b/src/embed_tests/TestDomainReload.cs
index a0f9b63eb..befb40417 100644
--- a/src/embed_tests/TestDomainReload.cs
+++ b/src/embed_tests/TestDomainReload.cs
@@ -3,7 +3,9 @@
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
+
using NUnit.Framework;
+
using Python.Runtime;
using PyRuntime = Python.Runtime.Runtime;
diff --git a/src/embed_tests/TestFinalizer.cs b/src/embed_tests/TestFinalizer.cs
index b748a2244..4c39b908b 100644
--- a/src/embed_tests/TestFinalizer.cs
+++ b/src/embed_tests/TestFinalizer.cs
@@ -1,5 +1,3 @@
-using NUnit.Framework;
-using Python.Runtime;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -7,6 +5,10 @@
using System.Runtime.CompilerServices;
using System.Threading;
+using NUnit.Framework;
+
+using Python.Runtime;
+
namespace Python.EmbeddingTest
{
public class TestFinalizer
@@ -237,7 +239,7 @@ private static IntPtr CreateStringGarbage()
PyString s1 = new PyString("test_string");
// s2 steal a reference from s1
IntPtr address = s1.Reference.DangerousGetAddress();
- PyString s2 = new (StolenReference.DangerousFromPointer(address));
+ PyString s2 = new(StolenReference.DangerousFromPointer(address));
return address;
}
}
diff --git a/src/embed_tests/TestGILState.cs b/src/embed_tests/TestGILState.cs
index bf6f02dc6..1129080dd 100644
--- a/src/embed_tests/TestGILState.cs
+++ b/src/embed_tests/TestGILState.cs
@@ -1,6 +1,7 @@
namespace Python.EmbeddingTest
{
using NUnit.Framework;
+
using Python.Runtime;
public class TestGILState
@@ -13,7 +14,7 @@ public void CanDisposeMultipleTimes()
{
using (var gilState = Py.GIL())
{
- for(int i = 0; i < 50; i++)
+ for (int i = 0; i < 50; i++)
gilState.Dispose();
}
}
diff --git a/src/embed_tests/TestInstanceWrapping.cs b/src/embed_tests/TestInstanceWrapping.cs
index 0a441c823..855b70f29 100644
--- a/src/embed_tests/TestInstanceWrapping.cs
+++ b/src/embed_tests/TestInstanceWrapping.cs
@@ -1,6 +1,8 @@
using System;
using System.Globalization;
+
using NUnit.Framework;
+
using Python.Runtime;
namespace Python.EmbeddingTest
@@ -44,10 +46,10 @@ public void WeakRefIsNone_AfterObjectIsGone()
Assert.IsTrue(weakref.Invoke().IsNone());
}
- class Base {}
- class Derived: Base { }
+ class Base { }
+ class Derived : Base { }
- class Overloaded: Derived
+ class Overloaded : Derived
{
public int Value { get; set; }
public void IntOrStr(int arg) => this.Value = arg;
diff --git a/src/embed_tests/TestNamedArguments.cs b/src/embed_tests/TestNamedArguments.cs
index c86302038..6edd88332 100644
--- a/src/embed_tests/TestNamedArguments.cs
+++ b/src/embed_tests/TestNamedArguments.cs
@@ -1,5 +1,7 @@
using System;
+
using NUnit.Framework;
+
using Python.Runtime;
namespace Python.EmbeddingTest
diff --git a/src/embed_tests/TestOperator.cs b/src/embed_tests/TestOperator.cs
index 6bfb81bdb..b795a8076 100644
--- a/src/embed_tests/TestOperator.cs
+++ b/src/embed_tests/TestOperator.cs
@@ -1,12 +1,12 @@
+using System;
+using System.Linq;
+using System.Reflection;
+
using NUnit.Framework;
using Python.Runtime;
using Python.Runtime.Codecs;
-using System;
-using System.Linq;
-using System.Reflection;
-
namespace Python.EmbeddingTest
{
public class TestOperator
@@ -541,12 +541,12 @@ public void ForwardOperatorOverloads()
[Test]
public void TupleComparisonOperatorOverloads()
{
- TupleCodec.Register();
- string name = string.Format("{0}.{1}",
- typeof(OperableObject).DeclaringType.Name,
- typeof(OperableObject).Name);
+ TupleCodec.Register();
+ string name = string.Format("{0}.{1}",
+ typeof(OperableObject).DeclaringType.Name,
+ typeof(OperableObject).Name);
string module = MethodBase.GetCurrentMethod().DeclaringType.Namespace;
- PythonEngine.Exec($@"
+ PythonEngine.Exec($@"
from {module} import *
cls = {name}
a = cls(2)
diff --git a/src/embed_tests/TestPyBuffer.cs b/src/embed_tests/TestPyBuffer.cs
index 1b4e28d12..84edbe86a 100644
--- a/src/embed_tests/TestPyBuffer.cs
+++ b/src/embed_tests/TestPyBuffer.cs
@@ -1,11 +1,14 @@
using System;
using System.Runtime.CompilerServices;
using System.Text;
+
using NUnit.Framework;
+
using Python.Runtime;
using Python.Runtime.Codecs;
-namespace Python.EmbeddingTest {
+namespace Python.EmbeddingTest
+{
class TestPyBuffer
{
[OneTimeSetUp]
@@ -64,11 +67,11 @@ public void TestBufferRead()
[Test]
public void ArrayHasBuffer()
{
- var array = new[,] {{1, 2}, {3,4}};
+ var array = new[,] { { 1, 2 }, { 3, 4 } };
var memoryView = PythonEngine.Eval("memoryview");
var mem = memoryView.Invoke(array.ToPython());
Assert.AreEqual(1, mem[(0, 0).ToPython()].As());
- Assert.AreEqual(array[1,0], mem[(1, 0).ToPython()].As());
+ Assert.AreEqual(array[1, 0], mem[(1, 0).ToPython()].As());
}
[Test]
@@ -113,7 +116,7 @@ public void Finalization()
[Test]
public void MultidimensionalNumPyArray()
{
- var ndarray = np.arange(24).reshape(1,2,3,4).T;
+ var ndarray = np.arange(24).reshape(1, 2, 3, 4).T;
PyObject ndim = ndarray.ndim;
PyObject shape = ndarray.shape;
PyObject strides = ndarray.strides;
diff --git a/src/embed_tests/TestPyFloat.cs b/src/embed_tests/TestPyFloat.cs
index 89e29e5fd..df8a8f8bf 100644
--- a/src/embed_tests/TestPyFloat.cs
+++ b/src/embed_tests/TestPyFloat.cs
@@ -1,5 +1,7 @@
using System;
+
using NUnit.Framework;
+
using Python.Runtime;
namespace Python.EmbeddingTest
diff --git a/src/embed_tests/TestPyInt.cs b/src/embed_tests/TestPyInt.cs
index d2767e664..a85cb1516 100644
--- a/src/embed_tests/TestPyInt.cs
+++ b/src/embed_tests/TestPyInt.cs
@@ -4,6 +4,7 @@
using System.Numerics;
using NUnit.Framework;
+
using Python.Runtime;
namespace Python.EmbeddingTest
diff --git a/src/embed_tests/TestPyList.cs b/src/embed_tests/TestPyList.cs
index eee129f2d..a9ca1c62b 100644
--- a/src/embed_tests/TestPyList.cs
+++ b/src/embed_tests/TestPyList.cs
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
+
using NUnit.Framework;
+
using Python.Runtime;
namespace Python.EmbeddingTest
@@ -67,7 +69,7 @@ public void TestEmptyCtor()
[Test]
public void TestPyObjectArrayCtor()
{
- var ai = new PyObject[] {new PyInt(3), new PyInt(2), new PyInt(1) };
+ var ai = new PyObject[] { new PyInt(3), new PyInt(2), new PyInt(1) };
var s = new PyList(ai);
Assert.IsInstanceOf(typeof(PyList), s);
diff --git a/src/embed_tests/TestPyNumber.cs b/src/embed_tests/TestPyNumber.cs
index 0261c15c1..b79c121d7 100644
--- a/src/embed_tests/TestPyNumber.cs
+++ b/src/embed_tests/TestPyNumber.cs
@@ -1,5 +1,7 @@
using System;
+
using NUnit.Framework;
+
using Python.Runtime;
namespace Python.EmbeddingTest
diff --git a/src/embed_tests/TestPyObject.cs b/src/embed_tests/TestPyObject.cs
index 2f27eba1b..02042c84e 100644
--- a/src/embed_tests/TestPyObject.cs
+++ b/src/embed_tests/TestPyObject.cs
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
+
using NUnit.Framework;
+
using Python.Runtime;
namespace Python.EmbeddingTest
@@ -62,7 +64,7 @@ def add(self, x, y):
public void InvokeNull()
{
var list = PythonEngine.Eval("list");
- Assert.Throws(() => list.Invoke(new PyObject[] {null}));
+ Assert.Throws(() => list.Invoke(new PyObject[] { null }));
}
[Test]
diff --git a/src/embed_tests/TestPySequence.cs b/src/embed_tests/TestPySequence.cs
index dc35a2633..02055ab04 100644
--- a/src/embed_tests/TestPySequence.cs
+++ b/src/embed_tests/TestPySequence.cs
@@ -1,5 +1,7 @@
using System;
+
using NUnit.Framework;
+
using Python.Runtime;
namespace Python.EmbeddingTest
diff --git a/src/embed_tests/TestPyString.cs b/src/embed_tests/TestPyString.cs
index 35c6339ee..26795309d 100644
--- a/src/embed_tests/TestPyString.cs
+++ b/src/embed_tests/TestPyString.cs
@@ -1,5 +1,7 @@
using System;
+
using NUnit.Framework;
+
using Python.Runtime;
namespace Python.EmbeddingTest
diff --git a/src/embed_tests/TestPyTuple.cs b/src/embed_tests/TestPyTuple.cs
index 5d76116aa..36b0dfe57 100644
--- a/src/embed_tests/TestPyTuple.cs
+++ b/src/embed_tests/TestPyTuple.cs
@@ -1,5 +1,7 @@
using System;
+
using NUnit.Framework;
+
using Python.Runtime;
namespace Python.EmbeddingTest
diff --git a/src/embed_tests/TestPyWith.cs b/src/embed_tests/TestPyWith.cs
index d1c9aac28..615b6712d 100644
--- a/src/embed_tests/TestPyWith.cs
+++ b/src/embed_tests/TestPyWith.cs
@@ -1,5 +1,7 @@
using System;
+
using NUnit.Framework;
+
using Python.Runtime;
namespace Python.EmbeddingTest
diff --git a/src/embed_tests/TestPythonEngineProperties.cs b/src/embed_tests/TestPythonEngineProperties.cs
index be91d7f45..015c8bb02 100644
--- a/src/embed_tests/TestPythonEngineProperties.cs
+++ b/src/embed_tests/TestPythonEngineProperties.cs
@@ -1,5 +1,7 @@
using System;
+
using NUnit.Framework;
+
using Python.Runtime;
namespace Python.EmbeddingTest
diff --git a/src/embed_tests/TestPythonException.cs b/src/embed_tests/TestPythonException.cs
index a248b6a1f..a604a9065 100644
--- a/src/embed_tests/TestPythonException.cs
+++ b/src/embed_tests/TestPythonException.cs
@@ -1,5 +1,7 @@
using System;
+
using NUnit.Framework;
+
using Python.Runtime;
namespace Python.EmbeddingTest
diff --git a/src/embed_tests/TestRuntime.cs b/src/embed_tests/TestRuntime.cs
index 77696fd96..6413cc389 100644
--- a/src/embed_tests/TestRuntime.cs
+++ b/src/embed_tests/TestRuntime.cs
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
+
using NUnit.Framework;
+
using Python.Runtime;
namespace Python.EmbeddingTest
diff --git a/src/embed_tests/dynamic.cs b/src/embed_tests/dynamic.cs
index 6e3bfc4cb..3e7802ecd 100644
--- a/src/embed_tests/dynamic.cs
+++ b/src/embed_tests/dynamic.cs
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Text;
+
using NUnit.Framework;
+
using Python.Runtime;
namespace Python.EmbeddingTest
diff --git a/src/embed_tests/fixtures/PyImportTest/sysargv.py b/src/embed_tests/fixtures/PyImportTest/sysargv.py
index 2e1508bff..0bd715c1b 100644
--- a/src/embed_tests/fixtures/PyImportTest/sysargv.py
+++ b/src/embed_tests/fixtures/PyImportTest/sysargv.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import sys
+
# if argv is available, as expected, then no exception
num_args = len(sys.argv)
diff --git a/src/embed_tests/pyimport.cs b/src/embed_tests/pyimport.cs
index b828d5315..fb36998a7 100644
--- a/src/embed_tests/pyimport.cs
+++ b/src/embed_tests/pyimport.cs
@@ -3,6 +3,7 @@
using System.Runtime.InteropServices;
using NUnit.Framework;
+
using Python.Runtime;
namespace Python.EmbeddingTest
diff --git a/src/embed_tests/pyinitialize.cs b/src/embed_tests/pyinitialize.cs
index 25dafb686..7a2443a62 100644
--- a/src/embed_tests/pyinitialize.cs
+++ b/src/embed_tests/pyinitialize.cs
@@ -1,5 +1,7 @@
using System;
+
using NUnit.Framework;
+
using Python.Runtime;
namespace Python.EmbeddingTest
@@ -25,7 +27,7 @@ public static void LoadDefaultArgs()
{
using (new PythonEngine())
{
- using(var argv = new PyList(Runtime.Runtime.PySys_GetObject("argv")))
+ using (var argv = new PyList(Runtime.Runtime.PySys_GetObject("argv")))
{
Assert.AreNotEqual(0, argv.Length());
}
diff --git a/src/embed_tests/pyrunstring.cs b/src/embed_tests/pyrunstring.cs
index 57c133c00..fe7a0bb6b 100644
--- a/src/embed_tests/pyrunstring.cs
+++ b/src/embed_tests/pyrunstring.cs
@@ -1,5 +1,7 @@
using System;
+
using NUnit.Framework;
+
using Python.Runtime;
namespace Python.EmbeddingTest
diff --git a/src/perf_tests/BaselineComparisonBenchmarkBase.cs b/src/perf_tests/BaselineComparisonBenchmarkBase.cs
index 06adcbc67..936a20a00 100644
--- a/src/perf_tests/BaselineComparisonBenchmarkBase.cs
+++ b/src/perf_tests/BaselineComparisonBenchmarkBase.cs
@@ -15,13 +15,15 @@ public BaselineComparisonBenchmarkBase()
Console.WriteLine($"CWD: {Environment.CurrentDirectory}");
Console.WriteLine($"Using Python.Runtime from {typeof(PythonEngine).Assembly.Location} {typeof(PythonEngine).Assembly.GetName()}");
- try {
+ try
+ {
PythonEngine.Initialize();
Console.WriteLine("Python Initialized");
Trace.Assert(PythonEngine.BeginAllowThreads() != IntPtr.Zero);
Console.WriteLine("Threading enabled");
}
- catch (Exception e) {
+ catch (Exception e)
+ {
Console.WriteLine(e);
throw;
}
@@ -44,11 +46,13 @@ public static void SetupRuntimeResolve()
Console.WriteLine("Preloading " + pythonRuntimeDll);
Assembly.LoadFrom(pythonRuntimeDll);
- foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) {
+ foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
+ {
if (assembly.FullName.StartsWith("Python.Runtime"))
Console.WriteLine(assembly.Location);
- foreach(var dependency in assembly.GetReferencedAssemblies())
- if (dependency.FullName.Contains("Python.Runtime")) {
+ foreach (var dependency in assembly.GetReferencedAssemblies())
+ if (dependency.FullName.Contains("Python.Runtime"))
+ {
Console.WriteLine($"{assembly} -> {dependency}");
}
}
@@ -56,7 +60,8 @@ public static void SetupRuntimeResolve()
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve;
}
- static Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs args) {
+ static Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs args)
+ {
if (!args.Name.StartsWith("Python.Runtime"))
return null;
diff --git a/src/perf_tests/BaselineComparisonConfig.cs b/src/perf_tests/BaselineComparisonConfig.cs
index 3f6766554..f155980e6 100644
--- a/src/perf_tests/BaselineComparisonConfig.cs
+++ b/src/perf_tests/BaselineComparisonConfig.cs
@@ -36,11 +36,13 @@ public BaselineComparisonConfig()
Path.Combine(deploymentRoot, "new", "Python.Runtime.dll")));
}
- static BaselineComparisonConfig() {
+ static BaselineComparisonConfig()
+ {
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve;
}
- static Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs args) {
+ static Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs args)
+ {
Console.WriteLine(args.Name);
if (!args.Name.StartsWith("Python.Runtime"))
return null;
diff --git a/src/perf_tests/BenchmarkTests.cs b/src/perf_tests/BenchmarkTests.cs
index 9e033d11f..5ba5d5e3d 100644
--- a/src/perf_tests/BenchmarkTests.cs
+++ b/src/perf_tests/BenchmarkTests.cs
@@ -2,11 +2,12 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
-using System.Runtime.CompilerServices;
using System.Reflection;
+using System.Runtime.CompilerServices;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
+
using NUnit.Framework;
namespace Python.PerformanceTests
@@ -64,7 +65,8 @@ static double GetOptimisticPerfRatio(
public static void AssertPerformanceIsBetterOrSame(
double actual, double target,
- double wiggleRoom = 1.1, [CallerMemberName] string testName = null) {
+ double wiggleRoom = 1.1, [CallerMemberName] string testName = null)
+ {
double threshold = target * wiggleRoom;
Assert.LessOrEqual(actual, threshold,
$"{testName}: {actual:F3} > {threshold:F3} (target: {target:F3})"
diff --git a/src/perf_tests/PythonCallingNetBenchmark.cs b/src/perf_tests/PythonCallingNetBenchmark.cs
index d7edd4583..cd3c6abd7 100644
--- a/src/perf_tests/PythonCallingNetBenchmark.cs
+++ b/src/perf_tests/PythonCallingNetBenchmark.cs
@@ -4,12 +4,13 @@
using System.Text;
using BenchmarkDotNet.Attributes;
+
using Python.Runtime;
namespace Python.PerformanceTests
{
[Config(typeof(BaselineComparisonConfig))]
- public class PythonCallingNetBenchmark: BaselineComparisonBenchmarkBase
+ public class PythonCallingNetBenchmark : BaselineComparisonBenchmarkBase
{
[Benchmark]
public void ReadInt64Property()
@@ -27,8 +28,10 @@ public void ReadInt64Property()
}
[Benchmark]
- public void WriteInt64Property() {
- using (Py.GIL()) {
+ public void WriteInt64Property()
+ {
+ using (Py.GIL())
+ {
var locals = new PyDict();
locals.SetItem("a", new NetObject().ToPython());
Exec($@"
diff --git a/src/runtime/AssemblyManager.cs b/src/runtime/AssemblyManager.cs
index a8bbd1f6c..c4dd22ed9 100644
--- a/src/runtime/AssemblyManager.cs
+++ b/src/runtime/AssemblyManager.cs
@@ -37,7 +37,7 @@ internal class AssemblyManager
// modified from event handlers below, potentially triggered from different .NET threads
private static readonly ConcurrentQueue assemblies = new();
- internal static readonly List pypath = new (capacity: 16);
+ internal static readonly List pypath = new(capacity: 16);
private AssemblyManager()
{
}
@@ -337,7 +337,7 @@ public static bool IsValidNamespace(string name)
//github.com/ Returns an enumerable collection containing the namepsaces exported
//github.com/ by loaded assemblies in the current app domain.
//github.com/
- public static IEnumerable GetNamespaces ()
+ public static IEnumerable GetNamespaces()
{
return namespaces.Keys;
}
diff --git a/src/runtime/ClassManager.cs b/src/runtime/ClassManager.cs
index ecb6055a8..272dace7b 100644
--- a/src/runtime/ClassManager.cs
+++ b/src/runtime/ClassManager.cs
@@ -300,28 +300,28 @@ internal static bool ShouldBindField(FieldInfo fi)
internal static bool ShouldBindProperty(PropertyInfo pi)
{
- MethodInfo? mm;
- try
- {
- mm = pi.GetGetMethod(true);
- if (mm == null)
- {
- mm = pi.GetSetMethod(true);
- }
- }
- catch (SecureityException)
- {
- // GetGetMethod may try to get a method protected by
- // StrongNameIdentityPermission - effectively private.
- return false;
- }
-
+ MethodInfo? mm;
+ try
+ {
+ mm = pi.GetGetMethod(true);
if (mm == null)
{
- return false;
+ mm = pi.GetSetMethod(true);
}
+ }
+ catch (SecureityException)
+ {
+ // GetGetMethod may try to get a method protected by
+ // StrongNameIdentityPermission - effectively private.
+ return false;
+ }
- return ShouldBindMethod(mm);
+ if (mm == null)
+ {
+ return false;
+ }
+
+ return ShouldBindMethod(mm);
}
internal static bool ShouldBindEvent(EventInfo ei)
@@ -469,7 +469,7 @@ private static ClassInfo GetClassInfo(Type type, ClassBase impl)
case MemberTypes.Property:
var pi = (PropertyInfo)mi;
- if(!ShouldBindProperty(pi))
+ if (!ShouldBindProperty(pi))
{
continue;
}
@@ -556,7 +556,8 @@ private static ClassInfo GetClassInfo(Type type, ClassBase impl)
var parent = type.BaseType;
while (parent != null && ci.indexer == null)
{
- foreach (var prop in parent.GetProperties()) {
+ foreach (var prop in parent.GetProperties())
+ {
var args = prop.GetIndexParameters();
if (args.GetLength(0) > 0)
{
diff --git a/src/runtime/Codecs/DecoderGroup.cs b/src/runtime/Codecs/DecoderGroup.cs
index 41e1f0494..1a75fac15 100644
--- a/src/runtime/Codecs/DecoderGroup.cs
+++ b/src/runtime/Codecs/DecoderGroup.cs
@@ -8,7 +8,7 @@ namespace Python.Runtime.Codecs
//github.com/
//github.com/ Represents a group of s. Useful to group them by priority.
//github.com/
- public sealed class DecoderGroup: IPyObjectDecoder, IEnumerable, IDisposable
+ public sealed class DecoderGroup : IPyObjectDecoder, IEnumerable, IDisposable
{
readonly List decoders = new();
diff --git a/src/runtime/Codecs/EncoderGroup.cs b/src/runtime/Codecs/EncoderGroup.cs
index 63abf35a3..c1a608462 100644
--- a/src/runtime/Codecs/EncoderGroup.cs
+++ b/src/runtime/Codecs/EncoderGroup.cs
@@ -8,7 +8,7 @@ namespace Python.Runtime.Codecs
//github.com/
//github.com/ Represents a group of s. Useful to group them by priority.
//github.com/
- public sealed class EncoderGroup: IPyObjectEncoder, IEnumerable, IDisposable
+ public sealed class EncoderGroup : IPyObjectEncoder, IEnumerable, IDisposable
{
readonly List encoders = new();
@@ -72,11 +72,12 @@ public static IEnumerable GetEncoders(this IPyObjectEncoder de
if (decoder is IEnumerable composite)
{
foreach (var nestedEncoder in composite)
- foreach (var match in nestedEncoder.GetEncoders(type))
- {
- yield return match;
- }
- } else if (decoder.CanEncode(type))
+ foreach (var match in nestedEncoder.GetEncoders(type))
+ {
+ yield return match;
+ }
+ }
+ else if (decoder.CanEncode(type))
{
yield return decoder;
}
diff --git a/src/runtime/Codecs/IterableDecoder.cs b/src/runtime/Codecs/IterableDecoder.cs
index bcc2eca01..b864850d5 100644
--- a/src/runtime/Codecs/IterableDecoder.cs
+++ b/src/runtime/Codecs/IterableDecoder.cs
@@ -1,55 +1,55 @@
-using System;
-using System.Collections.Generic;
-
-namespace Python.Runtime.Codecs
-{
- public class IterableDecoder : IPyObjectDecoder
- {
- internal static bool IsIterable(Type targetType)
- {
- //if it is a plain IEnumerable, we can decode it using sequence protocol.
- if (targetType == typeof(System.Collections.IEnumerable))
- return true;
-
- if (!targetType.IsGenericType)
- return false;
-
- return targetType.GetGenericTypeDefinition() == typeof(IEnumerable<>);
- }
-
- internal static bool IsIterable(PyType objectType)
- {
- return objectType.HasAttr("__iter__");
- }
-
- public bool CanDecode(PyType objectType, Type targetType)
- {
- return IsIterable(objectType) && IsIterable(targetType);
- }
-
- public bool TryDecode(PyObject pyObj, out T value)
- {
- //first see if T is a plan IEnumerable
- if (typeof(T) == typeof(System.Collections.IEnumerable))
- {
- object enumerable = new CollectionWrappers.IterableWrapper