pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/pythonnet/pythonnet/commit/d2d3ba669f7f5a149d0077a7cc6b6e4872eb1bd7

fa.css" /> Modernise syntax a bit · pythonnet/pythonnet@d2d3ba6 · GitHub
Skip to content

Commit d2d3ba6

Browse files
committed
Modernise syntax a bit
1 parent 5eccd45 commit d2d3ba6

53 files changed

Lines changed: 420 additions & 529 deletions

Some content is hidden

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

src/runtime/AssemblyManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ internal class AssemblyManager
2323
// than it can end up referring to assemblies that are already unloaded (default behavior after unload appDomain -
2424
// unless LoaderOptimization.MultiDomain is used);
2525
// So for multidomain support it is better to have the dict. recreated for each app-domain initialization
26-
private static ConcurrentDictionary<string, ConcurrentDictionary<Assembly, string>> namespaces =
27-
new ConcurrentDictionary<string, ConcurrentDictionary<Assembly, string>>();
26+
private static readonly ConcurrentDictionary<string, ConcurrentDictionary<Assembly, string>> namespaces =
27+
new();
2828

2929
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
3030
// domain-level handlers are initialized in Initialize
@@ -33,7 +33,7 @@ internal class AssemblyManager
3333
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
3434

3535
// updated only under GIL?
36-
private static Dictionary<string, int> probed = new Dictionary<string, int>(32);
36+
private static readonly Dictionary<string, int> probed = new(32);
3737

3838
// modified from event handlers below, potentially triggered from different .NET threads
3939
private static readonly ConcurrentQueue<Assembly> assemblies = new();

src/runtime/ClassManager.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,9 @@ internal static void InitClassBase(Type type, ClassBase impl, ReflectedClrType p
247247
Runtime.PyDict_SetItem(dict, PyIdentifier.__doc__, doc.Borrow());
248248
}
249249

250-
var co = impl as ClassObject;
251250
// If this is a ClassObject AND it has constructors, generate a __doc__ attribute.
252251
// required that the ClassObject.ctors be changed to internal
253-
if (co != null)
252+
if (impl is ClassObject co)
254253
{
255254
if (co.NumCtors > 0 && !co.HasCustomNew())
256255
{

src/runtime/Codecs/DecoderGroup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Python.Runtime.Codecs
1010
//github.com/ </summary>
1111
public sealed class DecoderGroup: IPyObjectDecoder, IEnumerable<IPyObjectDecoder>, IDisposable
1212
{
13-
readonly List<IPyObjectDecoder> decoders = new List<IPyObjectDecoder>();
13+
readonly List<IPyObjectDecoder> decoders = new();
1414

1515
//github.com/ <summary>
1616
//github.com/ Add specified decoder to the group

src/runtime/Codecs/EncoderGroup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Python.Runtime.Codecs
1010
//github.com/ </summary>
1111
public sealed class EncoderGroup: IPyObjectEncoder, IEnumerable<IPyObjectEncoder>, IDisposable
1212
{
13-
readonly List<IPyObjectEncoder> encoders = new List<IPyObjectEncoder>();
13+
readonly List<IPyObjectEncoder> encoders = new();
1414

1515
//github.com/ <summary>
1616
//github.com/ Add specified encoder to the group

src/runtime/Codecs/PyObjectConversions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ namespace Python.Runtime
1515
//github.com/ </summary>
1616
public static class PyObjectConversions
1717
{
18-
static readonly DecoderGroup decoders = new DecoderGroup();
19-
static readonly EncoderGroup encoders = new EncoderGroup();
18+
static readonly DecoderGroup decoders = new();
19+
static readonly EncoderGroup encoders = new();
2020

2121
//github.com/ <summary>
2222
//github.com/ Registers specified encoder (marshaller)
@@ -62,7 +62,7 @@ public static void RegisterDecoder(IPyObjectDecoder decoder)
6262
}
6363

6464
static readonly ConcurrentDictionary<Type, IPyObjectEncoder[]>
65-
clrToPython = new ConcurrentDictionary<Type, IPyObjectEncoder[]>();
65+
clrToPython = new();
6666
static IPyObjectEncoder[] GetEncoders(Type type)
6767
{
6868
lock (encoders)

src/runtime/Converter.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ private Converter()
1818
{
1919
}
2020

21-
private static Type objectType;
22-
private static Type stringType;
23-
private static Type singleType;
24-
private static Type doubleType;
25-
private static Type int16Type;
26-
private static Type int32Type;
27-
private static Type int64Type;
28-
private static Type boolType;
29-
private static Type typeType;
21+
private static readonly Type objectType;
22+
private static readonly Type stringType;
23+
private static readonly Type singleType;
24+
private static readonly Type doubleType;
25+
private static readonly Type int16Type;
26+
private static readonly Type int32Type;
27+
private static readonly Type int64Type;
28+
private static readonly Type boolType;
29+
private static readonly Type typeType;
3030

3131
static Converter()
3232
{
@@ -151,8 +151,7 @@ internal static NewReference ToPython(object? value, Type type)
151151

152152
// it the type is a python subclass of a managed type then return the
153153
// underlying python object rather than construct a new wrapper object.
154-
var pyderived = value as IPythonDerivedType;
155-
if (null != pyderived)
154+
if (value is IPythonDerivedType pyderived)
156155
{
157156
if (!IsTransparentProxy(pyderived))
158157
return ClassDerivedObject.ToPython(pyderived);
@@ -161,7 +160,7 @@ internal static NewReference ToPython(object? value, Type type)
161160
// ModuleObjects are created in a way that their wrapping them as
162161
// a CLRObject fails, the ClassObject has no tpHandle. Return the
163162
// pyHandle as is, do not convert.
164-
if (value is ModuleObject modobj)
163+
if (value is ModuleObject)
165164
{
166165
throw new NotImplementedException();
167166
}

src/runtime/DelegateManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ namespace Python.Runtime
1515
//github.com/ </summary>
1616
internal class DelegateManager
1717
{
18-
private readonly Dictionary<Type,Type> cache = new Dictionary<Type, Type>();
18+
private readonly Dictionary<Type,Type> cache = new();
1919
private readonly Type basetype = typeof(Dispatcher);
2020
private readonly Type arrayType = typeof(object[]);
2121
private readonly Type voidtype = typeof(void);
2222
private readonly Type typetype = typeof(Type);
2323
private readonly Type pyobjType = typeof(PyObject);
24-
private readonly CodeGenerator codeGenerator = new CodeGenerator();
24+
private readonly CodeGenerator codeGenerator = new();
2525
private readonly ConstructorInfo arrayCtor;
2626
private readonly MethodInfo dispatch;
2727

@@ -309,7 +309,7 @@ protected Dispatcher(PyObject target, Type dtype)
309309
{
310310
tpName += $" of size {Runtime.PyTuple_Size(op)}";
311311
}
312-
StringBuilder sb = new StringBuilder();
312+
var sb = new StringBuilder();
313313
if (!isVoid) sb.Append(rtype.FullName);
314314
for (int i = 0; i < pi.Length; i++)
315315
{

src/runtime/Exceptions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,7 @@ public static bool SetError(Exception e)
196196
// might get a managed exception raised that is a wrapper for a
197197
// Python exception. In that case we'd rather have the real thing.
198198

199-
var pe = e as PythonException;
200-
if (pe != null)
199+
if (e is PythonException pe)
201200
{
202201
pe.Restore();
203202
return true;

src/runtime/Finalizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public ErrorArgs(Exception error)
4141
[DefaultValue(true)]
4242
public bool Enable { get; set; } = true;
4343

44-
private ConcurrentQueue<PendingFinalization> _objQueue = new();
44+
private readonly ConcurrentQueue<PendingFinalization> _objQueue = new();
4545
private readonly ConcurrentQueue<PendingFinalization> _derivedQueue = new();
4646
private readonly ConcurrentQueue<Py_buffer> _bufferQueue = new();
4747
private int _throttled;

src/runtime/InternString.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ public static void Shutdown()
6161

6262
public static string? GetManagedString(BorrowedReference op)
6363
{
64-
string s;
65-
if (TryGetInterned(op, out s))
64+
if (TryGetInterned(op, out string s))
6665
{
6766
return s;
6867
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy