Skip to content

Commit ac74383

Browse files
committed
fixed all warnings except explicit ones
mostly nullability annotations removed a little bit of dead code
1 parent 8754ed1 commit ac74383

Some content is hidden

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

42 files changed

+164
-160
lines changed

src/runtime/Codecs/DecoderGroup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void Add(IPyObjectDecoder item)
3030
public bool CanDecode(PyType objectType, Type targetType)
3131
=> this.decoders.Any(decoder => decoder.CanDecode(objectType, targetType));
3232
/// <inheritdoc />
33-
public bool TryDecode<T>(PyObject pyObj, out T value)
33+
public bool TryDecode<T>(PyObject pyObj, out T? value)
3434
{
3535
if (pyObj is null) throw new ArgumentNullException(nameof(pyObj));
3636

@@ -65,7 +65,7 @@ public static class DecoderGroupExtensions
6565
/// that can decode from <paramref name="objectType"/> to <paramref name="targetType"/>,
6666
/// or <c>null</c> if a matching decoder can not be found.
6767
/// </summary>
68-
public static IPyObjectDecoder GetDecoder(
68+
public static IPyObjectDecoder? GetDecoder(
6969
this IPyObjectDecoder decoder,
7070
PyType objectType, Type targetType)
7171
{

src/runtime/Codecs/EncoderGroup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void Add(IPyObjectEncoder item)
2828
/// <inheritdoc />
2929
public bool CanEncode(Type type) => this.encoders.Any(encoder => encoder.CanEncode(type));
3030
/// <inheritdoc />
31-
public PyObject TryEncode(object value)
31+
public PyObject? TryEncode(object value)
3232
{
3333
if (value is null) throw new ArgumentNullException(nameof(value));
3434

src/runtime/CollectionWrappers/IterableWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public IEnumerator<T> GetEnumerator()
3535
iterObject.Dispose();
3636
break;
3737
}
38-
yield return iterObject.Current.As<T>();
38+
yield return iterObject.Current.As<T>()!;
3939
}
4040
}
4141
}

src/runtime/CollectionWrappers/ListWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public T this[int index]
1616
{
1717
var item = Runtime.PyList_GetItem(pyObject, index);
1818
var pyItem = new PyObject(item);
19-
return pyItem.As<T>();
19+
return pyItem.As<T>()!;
2020
}
2121
set
2222
{

src/runtime/CustomMarshaler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static ICustomMarshaler GetInstance(string cookie)
7474
return Instance;
7575
}
7676

77-
public static string PtrToStringUni(IntPtr p)
77+
public static string? PtrToStringUni(IntPtr p)
7878
{
7979
if (p == IntPtr.Zero)
8080
{
@@ -134,7 +134,7 @@ public static IntPtr Py3UnicodePy2StringtoPtr(string s)
134134
/// <returns>
135135
/// Managed String
136136
/// </returns>
137-
public static string PtrToPy3UnicodePy2String(IntPtr p)
137+
public static string? PtrToPy3UnicodePy2String(IntPtr p)
138138
{
139139
return PtrToStringUni(p);
140140
}
@@ -184,7 +184,7 @@ public override IntPtr MarshalManagedToNative(object managedObj)
184184
return mem;
185185
}
186186

187-
public static ICustomMarshaler GetInstance(string cookie)
187+
public static ICustomMarshaler GetInstance(string? cookie)
188188
{
189189
return Instance;
190190
}

src/runtime/Python.Runtime.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
</ItemGroup>
6161

6262
<ItemGroup>
63+
<PackageReference Include="Lost.Compat.NullabilityAttributes" Version="0.0.4" PrivateAssets="All" />
64+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
6365
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
64-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
6566
</ItemGroup>
6667
</Project>

src/runtime/ReflectedClrType.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ internal void Restore(InterDomainContext context)
5353
{
5454
var cb = context.Storage.GetValue<ClassBase>("impl");
5555

56-
cb.Load(this, context);
56+
Debug.Assert(cb is not null);
57+
58+
cb!.Load(this, context);
5759

5860
Restore(cb);
5961
}

src/runtime/StateSerialization/CLRWrapperCollection.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using System.Collections.ObjectModel;
2+
using System.Diagnostics.CodeAnalysis;
23

34
namespace Python.Runtime;
45

56
public class CLRWrapperCollection : KeyedCollection<object, CLRMappedItem>
67
{
7-
public bool TryGetValue(object key, out CLRMappedItem value)
8+
public bool TryGetValue(object key, [NotNullWhen(true)] out CLRMappedItem? value)
89
{
910
if (Dictionary == null)
1011
{

src/runtime/StateSerialization/ClassManagerState.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
namespace Python.Runtime.StateSerialization;
55

6+
// Workaround for the lack of required properties: https://github.com/dotnet/csharplang/issues/3630
7+
// Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
8+
#pragma warning disable CS8618
9+
610
[Serializable]
711
internal class ClassManagerState
812
{

src/runtime/StateSerialization/ImportHookState.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33

44
namespace Python.Runtime.StateSerialization;
55

6+
// Workaround for the lack of required properties: https://github.com/dotnet/csharplang/issues/3630
7+
// Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
8+
#pragma warning disable CS8618
9+
610
[Serializable]
711
internal class ImportHookState
812
{
9-
public PyModule PyCLRModule { get; set; }
10-
public PyObject Root { get; set; }
11-
public Dictionary<PyString, PyObject> Modules { get; set; }
13+
public PyModule PyCLRModule { get; init; }
14+
public PyObject Root { get; init; }
15+
public Dictionary<PyString, PyObject> Modules { get; init; }
1216
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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