Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fixed all warnings except explicit ones#1635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
lostmsu merged 1 commit intopythonnet:masterfromlosttech:cleanup/fix-warnings
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletionssrc/runtime/Codecs/DecoderGroup.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,7 +30,7 @@ public void Add(IPyObjectDecoder item)
public bool CanDecode(PyType objectType, Type targetType)
=> this.decoders.Any(decoder => decoder.CanDecode(objectType, targetType));
/// <inheritdoc />
public bool TryDecode<T>(PyObject pyObj, out T value)
public bool TryDecode<T>(PyObject pyObj, out T? value)
{
if (pyObj is null) throw new ArgumentNullException(nameof(pyObj));

Expand DownExpand Up@@ -65,7 +65,7 @@ public static class DecoderGroupExtensions
/// that can decode from <paramref name="objectType"/> to <paramref name="targetType"/>,
/// or <c>null</c> if a matching decoder can not be found.
/// </summary>
public static IPyObjectDecoder GetDecoder(
public static IPyObjectDecoder? GetDecoder(
this IPyObjectDecoder decoder,
PyType objectType, Type targetType)
{
Expand Down
2 changes: 1 addition & 1 deletionsrc/runtime/Codecs/EncoderGroup.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,7 +28,7 @@ public void Add(IPyObjectEncoder item)
/// <inheritdoc />
public bool CanEncode(Type type) => this.encoders.Any(encoder => encoder.CanEncode(type));
/// <inheritdoc />
public PyObject TryEncode(object value)
public PyObject? TryEncode(object value)
{
if (value is null) throw new ArgumentNullException(nameof(value));

Expand Down
2 changes: 1 addition & 1 deletionsrc/runtime/CollectionWrappers/IterableWrapper.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,7 +35,7 @@ public IEnumerator<T> GetEnumerator()
iterObject.Dispose();
break;
}
yield return iterObject.Current.As<T>();
yield return iterObject.Current.As<T>()!;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletionsrc/runtime/CollectionWrappers/ListWrapper.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,7 +16,7 @@ public T this[int index]
{
var item = Runtime.PyList_GetItem(pyObject, index);
var pyItem = new PyObject(item);
return pyItem.As<T>();
return pyItem.As<T>()!;
}
set
{
Expand Down
6 changes: 3 additions & 3 deletionssrc/runtime/CustomMarshaler.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -74,7 +74,7 @@ public static ICustomMarshaler GetInstance(string cookie)
return Instance;
}

public static string PtrToStringUni(IntPtr p)
public static string? PtrToStringUni(IntPtr p)
{
if (p == IntPtr.Zero)
{
Expand DownExpand Up@@ -134,7 +134,7 @@ public static IntPtr Py3UnicodePy2StringtoPtr(string s)
/// <returns>
/// Managed String
/// </returns>
public static string PtrToPy3UnicodePy2String(IntPtr p)
public static string? PtrToPy3UnicodePy2String(IntPtr p)
{
return PtrToStringUni(p);
}
Expand DownExpand Up@@ -184,7 +184,7 @@ public override IntPtr MarshalManagedToNative(object managedObj)
return mem;
}

public static ICustomMarshaler GetInstance(string cookie)
public static ICustomMarshaler GetInstance(string? cookie)
{
return Instance;
}
Expand Down
3 changes: 2 additions & 1 deletionsrc/runtime/Python.Runtime.csproj
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -60,7 +60,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Lost.Compat.NullabilityAttributes" Version="0.0.4" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
</Project>
4 changes: 3 additions & 1 deletionsrc/runtime/ReflectedClrType.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -53,7 +53,9 @@ internal void Restore(InterDomainContext context)
{
var cb = context.Storage.GetValue<ClassBase>("impl");

cb.Load(this, context);
Debug.Assert(cb is not null);

cb!.Load(this, context);

Restore(cb);
}
Expand Down
3 changes: 2 additions & 1 deletionsrc/runtime/StateSerialization/CLRWrapperCollection.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;

namespace Python.Runtime;

public class CLRWrapperCollection : KeyedCollection<object, CLRMappedItem>
{
public bool TryGetValue(object key, out CLRMappedItem value)
public bool TryGetValue(object key,[NotNullWhen(true)]out CLRMappedItem? value)
{
if (Dictionary == null)
{
Expand Down
4 changes: 4 additions & 0 deletionssrc/runtime/StateSerialization/ClassManagerState.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,10 @@

namespace Python.Runtime.StateSerialization;

// Workaround for the lack of required properties: https://github.com/dotnet/csharplang/issues/3630
// Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
#pragma warning disable CS8618

[Serializable]
internal class ClassManagerState
{
Expand Down
10 changes: 7 additions & 3 deletionssrc/runtime/StateSerialization/ImportHookState.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,10 +3,14 @@

namespace Python.Runtime.StateSerialization;

// Workaround for the lack of required properties: https://github.com/dotnet/csharplang/issues/3630
// Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
#pragma warning disable CS8618

[Serializable]
internal class ImportHookState
{
public PyModule PyCLRModule { get;set; }
public PyObject Root { get;set; }
public Dictionary<PyString, PyObject> Modules { get;set; }
public PyModule PyCLRModule { get;init; }
public PyObject Root { get;init; }
public Dictionary<PyString, PyObject> Modules { get;init; }
}
6 changes: 2 additions & 4 deletionssrc/runtime/StateSerialization/MaybeMemberInfo.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,8 +7,6 @@ namespace Python.Runtime
[Serializable]
internal struct MaybeMemberInfo<T> : ISerializable where T : MemberInfo
{
public static implicit operator MaybeMemberInfo<T>(T ob) => new MaybeMemberInfo<T>(ob);

// .ToString() of the serialized object
const string SerializationDescription = "d";
// The ReflectedType of the object
Expand DownExpand Up@@ -50,8 +48,8 @@ public override string ToString()
public MaybeMemberInfo(T fi)
{
info = fi;
Description = info?.ToString();
if (info?.DeclaringType is not null)
Description = info.ToString();
if (info.DeclaringType is not null)
Description += " of " + info.DeclaringType;
deserializationException = null;
}
Expand Down
6 changes: 4 additions & 2 deletionssrc/runtime/StateSerialization/MaybeMethodBase.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.Serialization;
using System.Linq;
Expand All@@ -21,7 +22,7 @@ internal struct MaybeMethodBase<T> : ISerializable where T: MethodBase

public static implicit operator MaybeMethodBase<T> (T? ob) => new (ob);

string name;
string? name;
MethodBase? info;

[NonSerialized]
Expand All@@ -48,7 +49,8 @@ public T Value
}

public T UnsafeValue => (T)info!;
public string Name {get{return name;}}
public string? Name => name;
[MemberNotNullWhen(true, nameof(info))]
public bool Valid => info != null;

public override string ToString()
Expand Down
4 changes: 4 additions & 0 deletionssrc/runtime/StateSerialization/MetatypeState.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,10 @@

namespace Python.Runtime.StateSerialization;

// Workaround for the lack of required properties: https://github.com/dotnet/csharplang/issues/3630
// Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
#pragma warning disable CS8618

[Serializable]
internal class MetatypeState
{
Expand Down
14 changes: 9 additions & 5 deletionssrc/runtime/StateSerialization/PythonNetState.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,12 +2,16 @@

namespace Python.Runtime.StateSerialization;

// Workaround for the lack of required properties: https://github.com/dotnet/csharplang/issues/3630
// Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
#pragma warning disable CS8618

[Serializable]
internal class PythonNetState
{
public MetatypeState Metatype { get;set; }
public SharedObjectsState SharedObjects { get;set; }
public TypeManagerState Types { get;set; }
public ClassManagerState Classes { get;set; }
public ImportHookState ImportHookState { get;set; }
public MetatypeState Metatype { get;init; }
public SharedObjectsState SharedObjects { get;init; }
public TypeManagerState Types { get;init; }
public ClassManagerState Classes { get;init; }
public ImportHookState ImportHookState { get;init; }
}
12 changes: 8 additions & 4 deletionssrc/runtime/StateSerialization/SharedObjectsState.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,11 +3,15 @@

namespace Python.Runtime.StateSerialization;

// Workaround for the lack of required properties: https://github.com/dotnet/csharplang/issues/3630
// Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
#pragma warning disable CS8618

[Serializable]
internal class SharedObjectsState
{
public Dictionary<PyObject, CLRObject> InternalStores { get;set; }
public Dictionary<PyObject, ExtensionType> Extensions { get;set; }
public RuntimeDataStorage Wrappers { get;set; }
public Dictionary<PyObject, InterDomainContext> Contexts { get;set; }
public Dictionary<PyObject, CLRObject> InternalStores { get;init; }
public Dictionary<PyObject, ExtensionType> Extensions { get;init; }
public RuntimeDataStorage Wrappers { get;init; }
public Dictionary<PyObject, InterDomainContext> Contexts { get;init; }
}
4 changes: 4 additions & 0 deletionssrc/runtime/StateSerialization/TypeManagerState.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,10 @@

namespace Python.Runtime.StateSerialization;

// Workaround for the lack of required properties: https://github.com/dotnet/csharplang/issues/3630
// Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
#pragma warning disable CS8618

[Serializable]
internal class TypeManagerState
{
Expand Down
16 changes: 9 additions & 7 deletionssrc/runtime/Util.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -119,13 +119,6 @@ internal static void WriteCLong(BorrowedReference type, int offset, Int64 value)
}
}

/// <summary>
/// Null-coalesce: if <paramref name="primary"/> parameter is not
/// <see cref="IntPtr.Zero"/>, return it. Otherwise return <paramref name="fallback"/>.
/// </summary>
internal static IntPtr Coalesce(this IntPtr primary, IntPtr fallback)
=> primary == IntPtr.Zero ? fallback : primary;

/// <summary>
/// Gets substring after last occurrence of <paramref name="symbol"/>
/// </summary>
Expand All@@ -149,5 +142,14 @@ internal static string ReadStringResource(this System.Reflection.Assembly assemb
}

public static IEnumerator<T> GetEnumerator<T>(this IEnumerator<T> enumerator) => enumerator;

public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> source)
where T: class
{
foreach (var item in source)
{
if (item is not null) yield return item;
}
}
}
}
2 changes: 1 addition & 1 deletionsrc/runtime/assemblymanager.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -358,7 +358,7 @@ public static List<string> GetNames(string nsname)
//Dictionary<string, int> seen = new Dictionary<string, int>();
var names = new List<string>(8);

List<string> g = GenericUtil.GetGenericBaseNames(nsname);
List<string>? g = GenericUtil.GetGenericBaseNames(nsname);
if (g != null)
{
foreach (string n in g)
Expand Down
4 changes: 2 additions & 2 deletionssrc/runtime/classbase.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -67,7 +67,7 @@ public virtual NewReference type_subscript(BorrowedReference idx)
return Exceptions.RaiseTypeError(type.DeletedMessage);
}

Type target = GenericUtil.GenericForType(type.Value, types.Length);
Type? target = GenericUtil.GenericForType(type.Value, types.Length);

if (target != null)
{
Expand DownExpand Up@@ -396,7 +396,7 @@ protected override void OnSave(BorrowedReference ob, InterDomainContext context)
context.Storage.AddValue("impl", this);
}

protected override void OnLoad(BorrowedReference ob, InterDomainContext context)
protected override void OnLoad(BorrowedReference ob, InterDomainContext? context)
{
base.OnLoad(ob, context);
var gcHandle = GCHandle.Alloc(this);
Expand Down
6 changes: 3 additions & 3 deletionssrc/runtime/classderived.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -144,7 +144,7 @@ internal static NewReference ToPython(IPythonDerivedType obj)
internal static Type CreateDerivedType(string name,
Type baseType,
BorrowedReference py_dict,
string namespaceStr,
string? namespaceStr,
string? assemblyName,
string moduleName = "Python.Runtime.Dynamic.dll")
{
Expand DownExpand Up@@ -669,7 +669,7 @@ public class PythonDerivedType
/// method binding (i.e. it has been overridden in the derived python
/// class) it calls it, otherwise it calls the base method.
/// </summary>
public static T InvokeMethod<T>(IPythonDerivedType obj, string methodName, string origMethodName, object[] args)
public static T? InvokeMethod<T>(IPythonDerivedType obj, string methodName, string origMethodName, object[] args)
{
var self = GetPyObj(obj);

Expand DownExpand Up@@ -776,7 +776,7 @@ public static void InvokeMethodVoid(IPythonDerivedType obj, string methodName, s
args);
}

public static T InvokeGetProperty<T>(IPythonDerivedType obj, string propertyName)
public static T? InvokeGetProperty<T>(IPythonDerivedType obj, string propertyName)
{
var self = GetPyObj(obj);

Expand Down
2 changes: 1 addition & 1 deletionsrc/runtime/clrobject.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -59,7 +59,7 @@ internal static void Restore(object ob, BorrowedReference pyHandle, InterDomainC
co.OnLoad(pyHandle, context);
}

protected override void OnLoad(BorrowedReference ob, InterDomainContext context)
protected override void OnLoad(BorrowedReference ob, InterDomainContext? context)
{
base.OnLoad(ob, context);
GCHandle gc = GCHandle.Alloc(this);
Expand Down
2 changes: 1 addition & 1 deletionsrc/runtime/converterextensions.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -126,7 +126,7 @@ internal static bool TryDecode(BorrowedReference pyHandle, BorrowedReference pyT
Debug.Assert(PyType.IsType(sourceTypeRef));
var pyType = new PyType(sourceTypeRef, prevalidated: true);

IPyObjectDecoder decoder;
IPyObjectDecoder? decoder;
lock (decoders)
{
decoder = decoders.GetDecoder(pyType, targetType);
Expand Down
2 changes: 1 addition & 1 deletionsrc/runtime/extensiontype.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -95,7 +95,7 @@ public static int tp_clear(BorrowedReference ob)
return res;
}

protected override void OnLoad(BorrowedReference ob, InterDomainContext context)
protected override void OnLoad(BorrowedReference ob, InterDomainContext? context)
{
base.OnLoad(ob, context);
SetupGc(ob, Runtime.PyObject_TYPE(ob));
Expand Down
2 changes: 1 addition & 1 deletionsrc/runtime/fieldobject.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,7 @@ internal class FieldObject : ExtensionType

public FieldObject(FieldInfo info)
{
this.info = info;
this.info =new MaybeFieldInfo(info);
}

/// <summary>
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp