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

Commitac74383

Browse files
committed
fixed all warnings except explicit ones
mostly nullability annotationsremoved a little bit of dead code
1 parent8754ed1 commitac74383

File tree

42 files changed

+164
-160
lines changed

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
publicboolCanDecode(PyTypeobjectType,TypetargetType)
3131
=>this.decoders.Any(decoder=>decoder.CanDecode(objectType,targetType));
3232
/// <inheritdoc />
33-
publicboolTryDecode<T>(PyObjectpyObj,outTvalue)
33+
publicboolTryDecode<T>(PyObjectpyObj,outT?value)
3434
{
3535
if(pyObjisnull)thrownewArgumentNullException(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-
publicstaticIPyObjectDecoderGetDecoder(
68+
publicstaticIPyObjectDecoder?GetDecoder(
6969
thisIPyObjectDecoderdecoder,
7070
PyTypeobjectType,TypetargetType)
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
publicboolCanEncode(Typetype)=>this.encoders.Any(encoder=>encoder.CanEncode(type));
3030
/// <inheritdoc />
31-
publicPyObjectTryEncode(objectvalue)
31+
publicPyObject?TryEncode(objectvalue)
3232
{
3333
if(valueisnull)thrownewArgumentNullException(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-
yieldreturniterObject.Current.As<T>();
38+
yieldreturniterObject.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
varitem=Runtime.PyList_GetItem(pyObject,index);
1818
varpyItem=newPyObject(item);
19-
returnpyItem.As<T>();
19+
returnpyItem.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
returnInstance;
7575
}
7676

77-
publicstaticstringPtrToStringUni(IntPtrp)
77+
publicstaticstring?PtrToStringUni(IntPtrp)
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-
publicstaticstringPtrToPy3UnicodePy2String(IntPtrp)
137+
publicstaticstring?PtrToPy3UnicodePy2String(IntPtrp)
138138
{
139139
returnPtrToStringUni(p);
140140
}
@@ -184,7 +184,7 @@ public override IntPtr MarshalManagedToNative(object managedObj)
184184
returnmem;
185185
}
186186

187-
publicstaticICustomMarshalerGetInstance(stringcookie)
187+
publicstaticICustomMarshalerGetInstance(string?cookie)
188188
{
189189
returnInstance;
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+
<PackageReferenceInclude="Lost.Compat.NullabilityAttributes"Version="0.0.4"PrivateAssets="All" />
64+
<PackageReferenceInclude="Microsoft.SourceLink.GitHub"Version="1.1.1"PrivateAssets="All" />
6365
<PackageReferenceInclude="System.Reflection.Emit"Version="4.3.0" />
64-
<PackageReferenceInclude="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
varcb=context.Storage.GetValue<ClassBase>("impl");
5555

56-
cb.Load(this,context);
56+
Debug.Assert(cbis notnull);
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
usingSystem.Collections.ObjectModel;
2+
usingSystem.Diagnostics.CodeAnalysis;
23

34
namespacePython.Runtime;
45

56
publicclassCLRWrapperCollection:KeyedCollection<object,CLRMappedItem>
67
{
7-
publicboolTryGetValue(objectkey,outCLRMappedItemvalue)
8+
publicboolTryGetValue(objectkey,[NotNullWhen(true)]outCLRMappedItem?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
namespacePython.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 disableCS8618
9+
610
[Serializable]
711
internalclassClassManagerState
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
namespacePython.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 disableCS8618
9+
610
[Serializable]
711
internalclassImportHookState
812
{
9-
publicPyModulePyCLRModule{get;set;}
10-
publicPyObjectRoot{get;set;}
11-
publicDictionary<PyString,PyObject>Modules{get;set;}
13+
publicPyModulePyCLRModule{get;init;}
14+
publicPyObjectRoot{get;init;}
15+
publicDictionary<PyString,PyObject>Modules{get;init;}
1216
}

‎src/runtime/StateSerialization/MaybeMemberInfo.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ namespace Python.Runtime
77
[Serializable]
88
internalstructMaybeMemberInfo<T>:ISerializablewhereT:MemberInfo
99
{
10-
publicstaticimplicitoperatorMaybeMemberInfo<T>(Tob)=>newMaybeMemberInfo<T>(ob);
11-
1210
// .ToString() of the serialized object
1311
conststringSerializationDescription="d";
1412
// The ReflectedType of the object
@@ -50,8 +48,8 @@ public override string ToString()
5048
publicMaybeMemberInfo(Tfi)
5149
{
5250
info=fi;
53-
Description=info?.ToString();
54-
if(info?.DeclaringTypeis notnull)
51+
Description=info.ToString();
52+
if(info.DeclaringTypeis notnull)
5553
Description+=" of "+info.DeclaringType;
5654
deserializationException=null;
5755
}

‎src/runtime/StateSerialization/MaybeMethodBase.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
usingSystem;
2+
usingSystem.Diagnostics.CodeAnalysis;
23
usingSystem.Reflection;
34
usingSystem.Runtime.Serialization;
45
usingSystem.Linq;
@@ -21,7 +22,7 @@ internal struct MaybeMethodBase<T> : ISerializable where T: MethodBase
2122

2223
publicstaticimplicitoperatorMaybeMethodBase<T>(T?ob)=>new(ob);
2324

24-
stringname;
25+
string?name;
2526
MethodBase?info;
2627

2728
[NonSerialized]
@@ -48,7 +49,8 @@ public T Value
4849
}
4950

5051
publicTUnsafeValue=>(T)info!;
51-
publicstringName{get{returnname;}}
52+
publicstring?Name=>name;
53+
[MemberNotNullWhen(true,nameof(info))]
5254
publicboolValid=>info!=null;
5355

5456
publicoverridestringToString()

‎src/runtime/StateSerialization/MetatypeState.cs

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

33
namespacePython.Runtime.StateSerialization;
44

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

‎src/runtime/StateSerialization/PythonNetState.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
namespacePython.Runtime.StateSerialization;
44

5+
// Workaround for the lack of required properties: https://github.com/dotnet/csharplang/issues/3630
6+
// Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
7+
#pragma warning disableCS8618
8+
59
[Serializable]
610
internalclassPythonNetState
711
{
8-
publicMetatypeStateMetatype{get;set;}
9-
publicSharedObjectsStateSharedObjects{get;set;}
10-
publicTypeManagerStateTypes{get;set;}
11-
publicClassManagerStateClasses{get;set;}
12-
publicImportHookStateImportHookState{get;set;}
12+
publicMetatypeStateMetatype{get;init;}
13+
publicSharedObjectsStateSharedObjects{get;init;}
14+
publicTypeManagerStateTypes{get;init;}
15+
publicClassManagerStateClasses{get;init;}
16+
publicImportHookStateImportHookState{get;init;}
1317
}

‎src/runtime/StateSerialization/SharedObjectsState.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33

44
namespacePython.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 disableCS8618
9+
610
[Serializable]
711
internalclassSharedObjectsState
812
{
9-
publicDictionary<PyObject,CLRObject>InternalStores{get;set;}
10-
publicDictionary<PyObject,ExtensionType>Extensions{get;set;}
11-
publicRuntimeDataStorageWrappers{get;set;}
12-
publicDictionary<PyObject,InterDomainContext>Contexts{get;set;}
13+
publicDictionary<PyObject,CLRObject>InternalStores{get;init;}
14+
publicDictionary<PyObject,ExtensionType>Extensions{get;init;}
15+
publicRuntimeDataStorageWrappers{get;init;}
16+
publicDictionary<PyObject,InterDomainContext>Contexts{get;init;}
1317
}

‎src/runtime/StateSerialization/TypeManagerState.cs

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

44
namespacePython.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 disableCS8618
9+
610
[Serializable]
711
internalclassTypeManagerState
812
{

‎src/runtime/Util.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,6 @@ internal static void WriteCLong(BorrowedReference type, int offset, Int64 value)
119119
}
120120
}
121121

122-
/// <summary>
123-
/// Null-coalesce: if <paramref name="primary"/> parameter is not
124-
/// <see cref="IntPtr.Zero"/>, return it. Otherwise return <paramref name="fallback"/>.
125-
/// </summary>
126-
internalstaticIntPtrCoalesce(thisIntPtrprimary,IntPtrfallback)
127-
=>primary==IntPtr.Zero?fallback:primary;
128-
129122
/// <summary>
130123
/// Gets substring after last occurrence of <paramref name="symbol"/>
131124
/// </summary>
@@ -149,5 +142,14 @@ internal static string ReadStringResource(this System.Reflection.Assembly assemb
149142
}
150143

151144
publicstaticIEnumerator<T>GetEnumerator<T>(thisIEnumerator<T>enumerator)=>enumerator;
145+
146+
publicstaticIEnumerable<T>WhereNotNull<T>(thisIEnumerable<T?>source)
147+
whereT:class
148+
{
149+
foreach(variteminsource)
150+
{
151+
if(itemis notnull)yieldreturnitem;
152+
}
153+
}
152154
}
153155
}

‎src/runtime/assemblymanager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ public static List<string> GetNames(string nsname)
358358
//Dictionary<string, int> seen = new Dictionary<string, int>();
359359
varnames=newList<string>(8);
360360

361-
List<string>g=GenericUtil.GetGenericBaseNames(nsname);
361+
List<string>?g=GenericUtil.GetGenericBaseNames(nsname);
362362
if(g!=null)
363363
{
364364
foreach(stringning)

‎src/runtime/classbase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public virtual NewReference type_subscript(BorrowedReference idx)
6767
returnExceptions.RaiseTypeError(type.DeletedMessage);
6868
}
6969

70-
Typetarget=GenericUtil.GenericForType(type.Value,types.Length);
70+
Type?target=GenericUtil.GenericForType(type.Value,types.Length);
7171

7272
if(target!=null)
7373
{
@@ -396,7 +396,7 @@ protected override void OnSave(BorrowedReference ob, InterDomainContext context)
396396
context.Storage.AddValue("impl",this);
397397
}
398398

399-
protectedoverridevoidOnLoad(BorrowedReferenceob,InterDomainContextcontext)
399+
protectedoverridevoidOnLoad(BorrowedReferenceob,InterDomainContext?context)
400400
{
401401
base.OnLoad(ob,context);
402402
vargcHandle=GCHandle.Alloc(this);

‎src/runtime/classderived.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ internal static NewReference ToPython(IPythonDerivedType obj)
144144
internalstaticTypeCreateDerivedType(stringname,
145145
TypebaseType,
146146
BorrowedReferencepy_dict,
147-
stringnamespaceStr,
147+
string?namespaceStr,
148148
string?assemblyName,
149149
stringmoduleName="Python.Runtime.Dynamic.dll")
150150
{
@@ -669,7 +669,7 @@ public class PythonDerivedType
669669
/// method binding (i.e. it has been overridden in the derived python
670670
/// class) it calls it, otherwise it calls the base method.
671671
/// </summary>
672-
publicstaticTInvokeMethod<T>(IPythonDerivedTypeobj,stringmethodName,stringorigMethodName,object[]args)
672+
publicstaticT?InvokeMethod<T>(IPythonDerivedTypeobj,stringmethodName,stringorigMethodName,object[]args)
673673
{
674674
varself=GetPyObj(obj);
675675

@@ -776,7 +776,7 @@ public static void InvokeMethodVoid(IPythonDerivedType obj, string methodName, s
776776
args);
777777
}
778778

779-
publicstaticTInvokeGetProperty<T>(IPythonDerivedTypeobj,stringpropertyName)
779+
publicstaticT?InvokeGetProperty<T>(IPythonDerivedTypeobj,stringpropertyName)
780780
{
781781
varself=GetPyObj(obj);
782782

‎src/runtime/clrobject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ internal static void Restore(object ob, BorrowedReference pyHandle, InterDomainC
5959
co.OnLoad(pyHandle,context);
6060
}
6161

62-
protectedoverridevoidOnLoad(BorrowedReferenceob,InterDomainContextcontext)
62+
protectedoverridevoidOnLoad(BorrowedReferenceob,InterDomainContext?context)
6363
{
6464
base.OnLoad(ob,context);
6565
GCHandlegc=GCHandle.Alloc(this);

‎src/runtime/converterextensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ internal static bool TryDecode(BorrowedReference pyHandle, BorrowedReference pyT
126126
Debug.Assert(PyType.IsType(sourceTypeRef));
127127
varpyType=newPyType(sourceTypeRef,prevalidated:true);
128128

129-
IPyObjectDecoderdecoder;
129+
IPyObjectDecoder?decoder;
130130
lock(decoders)
131131
{
132132
decoder=decoders.GetDecoder(pyType,targetType);

‎src/runtime/extensiontype.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static int tp_clear(BorrowedReference ob)
9595
returnres;
9696
}
9797

98-
protectedoverridevoidOnLoad(BorrowedReferenceob,InterDomainContextcontext)
98+
protectedoverridevoidOnLoad(BorrowedReferenceob,InterDomainContext?context)
9999
{
100100
base.OnLoad(ob,context);
101101
SetupGc(ob,Runtime.PyObject_TYPE(ob));

‎src/runtime/fieldobject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal class FieldObject : ExtensionType
1414

1515
publicFieldObject(FieldInfoinfo)
1616
{
17-
this.info=info;
17+
this.info=newMaybeFieldInfo(info);
1818
}
1919

2020
/// <summary>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp