diff --git a/eng/scripts/generate_exceptions.py b/eng/scripts/generate_exceptions.py index 9ce1294f2..563f35dfe 100644 --- a/eng/scripts/generate_exceptions.py +++ b/eng/scripts/generate_exceptions.py @@ -265,7 +265,7 @@ def get_clr_name(e): return e.replace('Error', '') + 'Exception' FACTORY = """ -public static Exception %(name)s(string format, params object[] args) { +public static Exception %(name)s(string format, params object?[] args) { return new %(clrname)s(string.Format(format, args)); }""" diff --git a/eng/scripts/generate_typecache.py b/eng/scripts/generate_typecache.py index 32eca2a36..2e53ddacf 100644 --- a/eng/scripts/generate_typecache.py +++ b/eng/scripts/generate_typecache.py @@ -74,21 +74,15 @@ def gen_typecache_storage(cw): types[x.typeType] = [x] for type in types: for a_type in types[type]: - cw.write('private static %s %s;' % (type, a_type.name)) + cw.write('private static %s? %s;' % (type, a_type.name)) # outputs the public getters for each cached type def gen_typecache(cw): for x in data: - cw.enter_block("public static %s %s" % (x.typeType, x.entryName)) - cw.enter_block("get") - - if x.typeType != 'PythonType': cast = '(%s)' % x.typeType - else: cast = "" - - cw.write("if (%s == null) %s = %sDynamicHelpers.GetPythonTypeFromType(typeof(%s));" % (x.name, x.name, cast, x.type)) - cw.write("return %s;" % x.name) - cw.exit_block() - cw.exit_block() + cw.write("public static %s %s" % (x.typeType, x.entryName)) + cw.indent() + cw.write("=> %s ??= DynamicHelpers.GetPythonTypeFromType(typeof(%s));" % (x.name, x.type)) + cw.dedent() cw.write("") def main(): diff --git a/src/core/IronPython/Runtime/Binding/BindingWarnings.cs b/src/core/IronPython/Runtime/Binding/BindingWarnings.cs index 9776e3297..ec50e9a4c 100644 --- a/src/core/IronPython/Runtime/Binding/BindingWarnings.cs +++ b/src/core/IronPython/Runtime/Binding/BindingWarnings.cs @@ -2,9 +2,11 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; +using System.Diagnostics.CodeAnalysis; using System.Linq.Expressions; -using System.Reflection; using System.Threading; using IronPython.Runtime.Exceptions; @@ -20,7 +22,7 @@ namespace IronPython.Runtime.Binding { /// Provides support for emitting warnings when built in methods are invoked at runtime. /// internal static class BindingWarnings { - public static bool ShouldWarn(PythonContext/*!*/ context, OverloadInfo/*!*/ method, out WarningInfo info) { + public static bool ShouldWarn(PythonContext/*!*/ context, OverloadInfo/*!*/ method, [NotNullWhen(true)] out WarningInfo? info) { Assert.NotNull(method); ObsoleteAttribute[] os = (ObsoleteAttribute[])method.ReflectionInfo.GetCustomAttributes(typeof(ObsoleteAttribute), true); @@ -39,25 +41,23 @@ public static bool ShouldWarn(PythonContext/*!*/ context, OverloadInfo/*!*/ meth #if FEATURE_APARTMENTSTATE // no apartment states on Silverlight - if (method.DeclaringType == typeof(Thread)) { - if (method.Name == "Sleep") { - info = new WarningInfo( - PythonExceptions.RuntimeWarning, - "Calling Thread.Sleep on an STA thread doesn't pump messages. Use Thread.CurrentThread.Join instead.", - Expression.Equal( - Expression.Call( - Expression.Property( - null, - typeof(Thread).GetProperty("CurrentThread") - ), - typeof(Thread).GetMethod("GetApartmentState") + if (method.DeclaringType == typeof(Thread) && method.Name == nameof(Thread.Sleep)) { + info = new WarningInfo( + PythonExceptions.RuntimeWarning, + "Calling Thread.Sleep on an STA thread doesn't pump messages. Use Thread.CurrentThread.Join instead.", + Expression.Equal( + Expression.Call( + Expression.Property( + null, + typeof(Thread).GetProperty(nameof(Thread.CurrentThread))! ), - AstUtils.Constant(ApartmentState.STA) - ) - ); + typeof(Thread).GetMethod(nameof(Thread.GetApartmentState))! + ), + AstUtils.Constant(ApartmentState.STA) + ) + ); - return true; - } + return true; } #endif diff --git a/src/core/IronPython/Runtime/Binding/CompatibilityInvokeBinder.cs b/src/core/IronPython/Runtime/Binding/CompatibilityInvokeBinder.cs index 1760542dc..397c335aa 100644 --- a/src/core/IronPython/Runtime/Binding/CompatibilityInvokeBinder.cs +++ b/src/core/IronPython/Runtime/Binding/CompatibilityInvokeBinder.cs @@ -2,19 +2,11 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System.Linq.Expressions; +#nullable enable -using System; -using System.Collections.Generic; -using System.Diagnostics; using System.Dynamic; -using Microsoft.Scripting; using Microsoft.Scripting.Actions; -using Microsoft.Scripting.Actions.Calls; -using Microsoft.Scripting.Utils; - -using IronPython.Runtime.Operations; using AstUtils = Microsoft.Scripting.Ast.Utils; @@ -32,7 +24,7 @@ public CompatibilityInvokeBinder(PythonContext/*!*/ context, CallInfo /*!*/ call _context = context; } - public override DynamicMetaObject/*!*/ FallbackInvoke(DynamicMetaObject target, DynamicMetaObject/*!*/[]/*!*/ args, DynamicMetaObject errorSuggestion) { + public override DynamicMetaObject/*!*/ FallbackInvoke(DynamicMetaObject target, DynamicMetaObject/*!*/[]/*!*/ args, DynamicMetaObject? errorSuggestion) { if (target.Value is IDynamicMetaObjectProvider && errorSuggestion == null) { // try creating an instance... return target.BindCreateInstance( @@ -51,7 +43,7 @@ public CompatibilityInvokeBinder(PythonContext/*!*/ context, CallInfo /*!*/ call return InvokeFallback(target, args, BindingHelpers.CallInfoToSignature(CallInfo), errorSuggestion); } - internal DynamicMetaObject/*!*/ InvokeFallback(DynamicMetaObject/*!*/ target, DynamicMetaObject/*!*/[]/*!*/ args, CallSignature sig, DynamicMetaObject errorSuggestion) { + internal DynamicMetaObject/*!*/ InvokeFallback(DynamicMetaObject/*!*/ target, DynamicMetaObject/*!*/[]/*!*/ args, CallSignature sig, DynamicMetaObject? errorSuggestion) { return PythonProtocol.Call(this, target, args) ?? Context.Binder.Create(sig, target, args, AstUtils.Constant(_context.SharedContext)) ?? @@ -62,7 +54,7 @@ public override int GetHashCode() { return base.GetHashCode() ^ _context.Binder.GetHashCode(); } - public override bool Equals(object obj) { + public override bool Equals(object? obj) { if (!(obj is CompatibilityInvokeBinder ob)) { return false; } diff --git a/src/core/IronPython/Runtime/Binding/ContextArgBuilder.cs b/src/core/IronPython/Runtime/Binding/ContextArgBuilder.cs index 33edf183f..05e4ace62 100644 --- a/src/core/IronPython/Runtime/Binding/ContextArgBuilder.cs +++ b/src/core/IronPython/Runtime/Binding/ContextArgBuilder.cs @@ -2,15 +2,12 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System.Linq.Expressions; +#nullable enable -using System.Collections.Generic; -using System.Diagnostics; +using System.Linq.Expressions; using System.Reflection; -using System; -using System.Dynamic; + using Microsoft.Scripting.Actions.Calls; -using Microsoft.Scripting.Utils; namespace IronPython.Runtime.Binding { diff --git a/src/core/IronPython/Runtime/Binding/CreateFallbackBinder.cs b/src/core/IronPython/Runtime/Binding/CreateFallbackBinder.cs index 2b6a9aaa0..5c4c51a5b 100644 --- a/src/core/IronPython/Runtime/Binding/CreateFallbackBinder.cs +++ b/src/core/IronPython/Runtime/Binding/CreateFallbackBinder.cs @@ -2,17 +2,9 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System.Linq.Expressions; +#nullable enable -using System; -using System.Collections.Generic; -using System.Diagnostics; using System.Dynamic; -using IronPython.Runtime.Operations; -using Microsoft.Scripting; -using Microsoft.Scripting.Actions; -using Microsoft.Scripting.Utils; -using AstUtils = Microsoft.Scripting.Ast.Utils; namespace IronPython.Runtime.Binding { /// @@ -27,7 +19,7 @@ public CreateFallback(CompatibilityInvokeBinder/*!*/ realFallback, CallInfo /*!* _fallback = realFallback; } - public override DynamicMetaObject/*!*/ FallbackCreateInstance(DynamicMetaObject/*!*/ target, DynamicMetaObject/*!*/[]/*!*/ args, DynamicMetaObject errorSuggestion) { + public override DynamicMetaObject/*!*/ FallbackCreateInstance(DynamicMetaObject/*!*/ target, DynamicMetaObject/*!*/[]/*!*/ args, DynamicMetaObject? errorSuggestion) { return _fallback.InvokeFallback(target, args, BindingHelpers.GetCallSignature(this), errorSuggestion); } diff --git a/src/core/IronPython/Runtime/Binding/FastBindResult.cs b/src/core/IronPython/Runtime/Binding/FastBindResult.cs index e6866a55c..78c5d675d 100644 --- a/src/core/IronPython/Runtime/Binding/FastBindResult.cs +++ b/src/core/IronPython/Runtime/Binding/FastBindResult.cs @@ -2,17 +2,9 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System.Linq.Expressions; - -using System; -using System.Dynamic; -using System.Runtime.CompilerServices; - -using Microsoft.Scripting.Actions; +#nullable enable namespace IronPython.Runtime.Binding { - using Ast = Expression; - internal readonly struct FastBindResult where T : class { public readonly T Target; public readonly bool ShouldCache; diff --git a/src/core/IronPython/Runtime/Binding/FastGetBase.cs b/src/core/IronPython/Runtime/Binding/FastGetBase.cs index bb849308c..08dc878a3 100644 --- a/src/core/IronPython/Runtime/Binding/FastGetBase.cs +++ b/src/core/IronPython/Runtime/Binding/FastGetBase.cs @@ -39,4 +39,4 @@ protected static object Update(CallSite site, object self, CodeContext context) return ((CallSite>)site).Update(site, self, context); } } -} \ No newline at end of file +} diff --git a/src/core/IronPython/Runtime/Binding/IComConvertible.cs b/src/core/IronPython/Runtime/Binding/IComConvertible.cs index 4fdb80c4a..fa8690e17 100644 --- a/src/core/IronPython/Runtime/Binding/IComConvertible.cs +++ b/src/core/IronPython/Runtime/Binding/IComConvertible.cs @@ -2,10 +2,9 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System; -using System.Collections.Generic; +#nullable enable + using System.Dynamic; -using System.Text; namespace IronPython.Runtime.Binding { /// diff --git a/src/core/IronPython/Runtime/Binding/IFastGettable.cs b/src/core/IronPython/Runtime/Binding/IFastGettable.cs index fc728450c..5b438c75d 100644 --- a/src/core/IronPython/Runtime/Binding/IFastGettable.cs +++ b/src/core/IronPython/Runtime/Binding/IFastGettable.cs @@ -2,12 +2,7 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System.Linq.Expressions; - -using System; -using System.Dynamic; - -using Microsoft.Scripting.Actions; +#nullable enable using System.Runtime.CompilerServices; diff --git a/src/core/IronPython/Runtime/Binding/IFastInvokable.cs b/src/core/IronPython/Runtime/Binding/IFastInvokable.cs index e0bf05d73..48863a7bb 100644 --- a/src/core/IronPython/Runtime/Binding/IFastInvokable.cs +++ b/src/core/IronPython/Runtime/Binding/IFastInvokable.cs @@ -2,12 +2,9 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System.Linq.Expressions; +#nullable enable -using System; -using System.Dynamic; using System.Runtime.CompilerServices; -using Microsoft.Scripting.Actions; namespace IronPython.Runtime.Binding { internal interface IFastInvokable { diff --git a/src/core/IronPython/Runtime/Binding/IFastSettable.cs b/src/core/IronPython/Runtime/Binding/IFastSettable.cs index dcfe19c99..570141fdf 100644 --- a/src/core/IronPython/Runtime/Binding/IFastSettable.cs +++ b/src/core/IronPython/Runtime/Binding/IFastSettable.cs @@ -2,14 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System.Linq.Expressions; +#nullable enable -using System; -using System.Dynamic; - -using Microsoft.Scripting.Actions; - -using Microsoft.Scripting.Runtime; using System.Runtime.CompilerServices; namespace IronPython.Runtime.Binding { diff --git a/src/core/IronPython/Runtime/Binding/IPythonConvertible.cs b/src/core/IronPython/Runtime/Binding/IPythonConvertible.cs index ceb0e3edc..d4ed534ab 100644 --- a/src/core/IronPython/Runtime/Binding/IPythonConvertible.cs +++ b/src/core/IronPython/Runtime/Binding/IPythonConvertible.cs @@ -2,11 +2,9 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System.Linq.Expressions; +#nullable enable -using System; using System.Dynamic; -using Microsoft.Scripting.Actions; namespace IronPython.Runtime.Binding { internal interface IPythonConvertible { diff --git a/src/core/IronPython/Runtime/Binding/IPythonGetable.cs b/src/core/IronPython/Runtime/Binding/IPythonGetable.cs index 468dbc2fe..77216976d 100644 --- a/src/core/IronPython/Runtime/Binding/IPythonGetable.cs +++ b/src/core/IronPython/Runtime/Binding/IPythonGetable.cs @@ -2,9 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System.Linq.Expressions; +#nullable enable -using System; using System.Dynamic; namespace IronPython.Runtime.Binding { diff --git a/src/core/IronPython/Runtime/Binding/IPythonInvokable.cs b/src/core/IronPython/Runtime/Binding/IPythonInvokable.cs index 217e75fe9..008a3a42a 100644 --- a/src/core/IronPython/Runtime/Binding/IPythonInvokable.cs +++ b/src/core/IronPython/Runtime/Binding/IPythonInvokable.cs @@ -2,10 +2,10 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System.Linq.Expressions; +#nullable enable -using System; using System.Dynamic; +using System.Linq.Expressions; namespace IronPython.Runtime.Binding { /// diff --git a/src/core/IronPython/Runtime/Binding/IPythonOperable.cs b/src/core/IronPython/Runtime/Binding/IPythonOperable.cs index e17eebd91..3927914ca 100644 --- a/src/core/IronPython/Runtime/Binding/IPythonOperable.cs +++ b/src/core/IronPython/Runtime/Binding/IPythonOperable.cs @@ -2,9 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System; -using System.Collections.Generic; -using System.Text; +#nullable enable + using System.Dynamic; namespace IronPython.Runtime.Binding { diff --git a/src/core/IronPython/Runtime/Binding/IPythonSite.cs b/src/core/IronPython/Runtime/Binding/IPythonSite.cs index d1aa81cd0..ad8879e93 100644 --- a/src/core/IronPython/Runtime/Binding/IPythonSite.cs +++ b/src/core/IronPython/Runtime/Binding/IPythonSite.cs @@ -1,6 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Text; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +#nullable enable namespace IronPython.Runtime.Binding { internal interface IPythonSite { diff --git a/src/core/IronPython/Runtime/Binding/MetaPythonObject.cs b/src/core/IronPython/Runtime/Binding/MetaPythonObject.cs index 3b0631a5c..f150ac9b4 100644 --- a/src/core/IronPython/Runtime/Binding/MetaPythonObject.cs +++ b/src/core/IronPython/Runtime/Binding/MetaPythonObject.cs @@ -2,16 +2,17 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System.Linq.Expressions; +#nullable enable using System; -using System.Diagnostics; using System.Dynamic; -using Microsoft.Scripting.Actions; +using System.Linq.Expressions; + +using IronPython.Runtime.Operations; +using IronPython.Runtime.Types; + using Microsoft.Scripting.Ast; using Microsoft.Scripting.Runtime; -using IronPython.Runtime.Types; -using IronPython.Runtime.Operations; namespace IronPython.Runtime.Binding { using Ast = Expression; @@ -37,7 +38,7 @@ public MetaPythonObject(Expression/*!*/ expression, BindingRestrictions/*!*/ res internal static MethodCallExpression MakeTryGetTypeMember(PythonContext/*!*/ PythonContext, PythonTypeSlot dts, Expression self, ParameterExpression tmp) { return MakeTryGetTypeMember( PythonContext, - dts, + dts, tmp, self, Ast.Property( @@ -96,15 +97,13 @@ public PythonType/*!*/ PythonType { /// TODO: This should be specialized for each callable object /// protected static DynamicMetaObject/*!*/ MakeDelegateTarget(DynamicMetaObjectBinder/*!*/ action, Type/*!*/ toType, DynamicMetaObject/*!*/ arg) { - Debug.Assert(arg != null); - PythonContext state = PythonContext.GetPythonContext(action); CodeContext context = state != null ? state.SharedContext : DefaultContext.Default; - + return new DynamicMetaObject( Ast.Convert( Ast.Call( - typeof(PythonOps).GetMethod(nameof(PythonOps.GetDelegate)), + typeof(PythonOps).GetMethod(nameof(PythonOps.GetDelegate))!, AstUtils.Constant(context), arg.Expression, AstUtils.Constant(toType) @@ -138,6 +137,5 @@ protected static string GetGetMemberName(DynamicMetaObjectBinder member) { return gma.Name; } - } } diff --git a/src/core/IronPython/Runtime/Binding/PythonDeleteIndexBinder.cs b/src/core/IronPython/Runtime/Binding/PythonDeleteIndexBinder.cs index 9b05ba4fe..f07969ae1 100644 --- a/src/core/IronPython/Runtime/Binding/PythonDeleteIndexBinder.cs +++ b/src/core/IronPython/Runtime/Binding/PythonDeleteIndexBinder.cs @@ -2,16 +2,17 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System.Linq.Expressions; +#nullable enable -using System; using System.Dynamic; +using System.Linq.Expressions; + +using IronPython.Runtime.Operations; using Microsoft.Scripting.Runtime; using Microsoft.Scripting.Utils; -using AstUtils = Microsoft.Scripting.Ast.Utils; -using IronPython.Runtime.Operations; +using AstUtils = Microsoft.Scripting.Ast.Utils; namespace IronPython.Runtime.Binding { using Ast = Expression; @@ -24,15 +25,15 @@ public PythonDeleteIndexBinder(PythonContext/*!*/ context, int argCount) _context = context; } - public override DynamicMetaObject FallbackDeleteIndex(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject errorSuggestion) { - return PythonProtocol.Index(this, PythonIndexType.DeleteItem, ArrayUtils.Insert(target, indexes),errorSuggestion); + public override DynamicMetaObject FallbackDeleteIndex(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject? errorSuggestion) { + return PythonProtocol.Index(this, PythonIndexType.DeleteItem, ArrayUtils.Insert(target, indexes), errorSuggestion); } public override int GetHashCode() { return base.GetHashCode() ^ _context.Binder.GetHashCode(); } - public override bool Equals(object obj) { + public override bool Equals(object? obj) { if (!(obj is PythonDeleteIndexBinder ob)) { return false; } @@ -52,7 +53,7 @@ public PythonContext/*!*/ Context { public Expression/*!*/ CreateExpression() { return Ast.Call( - typeof(PythonOps).GetMethod(nameof(PythonOps.MakeDeleteIndexAction)), + typeof(PythonOps).GetMethod(nameof(PythonOps.MakeDeleteIndexAction))!, BindingHelpers.CreateBinderStateExpression(), AstUtils.Constant(CallInfo.ArgumentCount) ); diff --git a/src/core/IronPython/Runtime/Binding/PythonDeleteMemberBinder.cs b/src/core/IronPython/Runtime/Binding/PythonDeleteMemberBinder.cs index 5c3ee8175..6337961c9 100644 --- a/src/core/IronPython/Runtime/Binding/PythonDeleteMemberBinder.cs +++ b/src/core/IronPython/Runtime/Binding/PythonDeleteMemberBinder.cs @@ -2,16 +2,14 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System.Linq.Expressions; +#nullable enable -using System; -using Microsoft.Scripting; using System.Dynamic; -using Microsoft.Scripting.Runtime; +using System.Linq.Expressions; -using IronPython.Runtime.Binding; using IronPython.Runtime.Operations; -using IronPython.Runtime.Types; + +using Microsoft.Scripting.Runtime; namespace IronPython.Runtime.Binding { using Ast = Expression; @@ -30,7 +28,7 @@ public PythonDeleteMemberBinder(PythonContext/*!*/ context, string/*!*/ name, bo _context = context; } - public override DynamicMetaObject FallbackDeleteMember(DynamicMetaObject self, DynamicMetaObject errorSuggestion) { + public override DynamicMetaObject FallbackDeleteMember(DynamicMetaObject self, DynamicMetaObject? errorSuggestion) { if (self.NeedsDeferral()) { return Defer(self); } @@ -48,7 +46,7 @@ public override int GetHashCode() { return base.GetHashCode() ^ _context.Binder.GetHashCode(); } - public override bool Equals(object obj) { + public override bool Equals(object? obj) { if (!(obj is PythonDeleteMemberBinder ob)) { return false; } @@ -64,7 +62,7 @@ public override string ToString() { public Expression CreateExpression() { return Ast.Call( - typeof(PythonOps).GetMethod(nameof(PythonOps.MakeDeleteAction)), + typeof(PythonOps).GetMethod(nameof(PythonOps.MakeDeleteAction))!, BindingHelpers.CreateBinderStateExpression(), AstUtils.Constant(Name) ); diff --git a/src/core/IronPython/Runtime/Binding/PythonDeleteSliceBinder.cs b/src/core/IronPython/Runtime/Binding/PythonDeleteSliceBinder.cs index af5c43ba1..e77e54e30 100644 --- a/src/core/IronPython/Runtime/Binding/PythonDeleteSliceBinder.cs +++ b/src/core/IronPython/Runtime/Binding/PythonDeleteSliceBinder.cs @@ -2,16 +2,16 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System.Linq.Expressions; +#nullable enable -using System; using System.Dynamic; +using System.Linq.Expressions; + +using IronPython.Runtime.Operations; using Microsoft.Scripting.Runtime; using Microsoft.Scripting.Utils; -using IronPython.Runtime.Operations; - namespace IronPython.Runtime.Binding { using Ast = Expression; @@ -30,7 +30,7 @@ public override int GetHashCode() { return base.GetHashCode() ^ _context.Binder.GetHashCode(); } - public override bool Equals(object obj) { + public override bool Equals(object? obj) { if (!(obj is PythonDeleteSliceBinder ob)) { return false; } @@ -50,7 +50,7 @@ public PythonContext/*!*/ Context { public Expression/*!*/ CreateExpression() { return Ast.Call( - typeof(PythonOps).GetMethod(nameof(PythonOps.MakeDeleteSliceBinder)), + typeof(PythonOps).GetMethod(nameof(PythonOps.MakeDeleteSliceBinder))!, BindingHelpers.CreateBinderStateExpression() ); } diff --git a/src/core/IronPython/Runtime/Binding/PythonGetSliceBinder.cs b/src/core/IronPython/Runtime/Binding/PythonGetSliceBinder.cs index 3cd18aaea..cf0cb1fb8 100644 --- a/src/core/IronPython/Runtime/Binding/PythonGetSliceBinder.cs +++ b/src/core/IronPython/Runtime/Binding/PythonGetSliceBinder.cs @@ -2,16 +2,16 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System.Linq.Expressions; +#nullable enable -using System; using System.Dynamic; +using System.Linq.Expressions; + +using IronPython.Runtime.Operations; using Microsoft.Scripting.Runtime; using Microsoft.Scripting.Utils; -using IronPython.Runtime.Operations; - namespace IronPython.Runtime.Binding { using Ast = Expression; @@ -30,7 +30,7 @@ public override int GetHashCode() { return base.GetHashCode() ^ _context.Binder.GetHashCode(); } - public override bool Equals(object obj) { + public override bool Equals(object? obj) { if (!(obj is PythonGetSliceBinder ob)) { return false; } @@ -50,7 +50,7 @@ public PythonContext/*!*/ Context { public Expression/*!*/ CreateExpression() { return Ast.Call( - typeof(PythonOps).GetMethod(nameof(PythonOps.MakeGetSliceBinder)), + typeof(PythonOps).GetMethod(nameof(PythonOps.MakeGetSliceBinder))!, BindingHelpers.CreateBinderStateExpression() ); } diff --git a/src/core/IronPython/Runtime/Binding/PythonIndexType.cs b/src/core/IronPython/Runtime/Binding/PythonIndexType.cs index bafaafefb..5ec89309c 100644 --- a/src/core/IronPython/Runtime/Binding/PythonIndexType.cs +++ b/src/core/IronPython/Runtime/Binding/PythonIndexType.cs @@ -2,9 +2,7 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System; -using System.Collections.Generic; -using System.Text; +#nullable enable namespace IronPython.Runtime.Binding { internal enum PythonIndexType { @@ -15,5 +13,4 @@ internal enum PythonIndexType { SetSlice, DeleteSlice } - } diff --git a/src/core/IronPython/Runtime/Binding/PythonOperationKind.cs b/src/core/IronPython/Runtime/Binding/PythonOperationKind.cs index a2f0112a8..3f540daed 100644 --- a/src/core/IronPython/Runtime/Binding/PythonOperationKind.cs +++ b/src/core/IronPython/Runtime/Binding/PythonOperationKind.cs @@ -1,6 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Text; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +#nullable enable namespace IronPython.Runtime.Binding { /// diff --git a/src/core/IronPython/Runtime/Binding/PythonSetSliceBinder.cs b/src/core/IronPython/Runtime/Binding/PythonSetSliceBinder.cs index db3f13b12..260f9e038 100644 --- a/src/core/IronPython/Runtime/Binding/PythonSetSliceBinder.cs +++ b/src/core/IronPython/Runtime/Binding/PythonSetSliceBinder.cs @@ -2,16 +2,15 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System.Linq.Expressions; +#nullable enable -using System; using System.Dynamic; - -using Microsoft.Scripting.Runtime; -using Microsoft.Scripting.Utils; +using System.Linq.Expressions; using IronPython.Runtime.Operations; +using Microsoft.Scripting.Runtime; +using Microsoft.Scripting.Utils; namespace IronPython.Runtime.Binding { using Ast = Expression; @@ -31,7 +30,7 @@ public override int GetHashCode() { return base.GetHashCode() ^ _context.Binder.GetHashCode(); } - public override bool Equals(object obj) { + public override bool Equals(object? obj) { if (!(obj is PythonSetSliceBinder ob)) { return false; } @@ -51,7 +50,7 @@ public PythonContext/*!*/ Context { public Expression/*!*/ CreateExpression() { return Ast.Call( - typeof(PythonOps).GetMethod(nameof(PythonOps.MakeSetSliceBinder)), + typeof(PythonOps).GetMethod(nameof(PythonOps.MakeSetSliceBinder))!, BindingHelpers.CreateBinderStateExpression() ); } diff --git a/src/core/IronPython/Runtime/Binding/SiteLocalStorageBuilder.cs b/src/core/IronPython/Runtime/Binding/SiteLocalStorageBuilder.cs index 949a9873d..4d8e44195 100644 --- a/src/core/IronPython/Runtime/Binding/SiteLocalStorageBuilder.cs +++ b/src/core/IronPython/Runtime/Binding/SiteLocalStorageBuilder.cs @@ -2,19 +2,19 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System.Linq.Expressions; +#nullable enable using System; -using System.Collections.Generic; -using System.Dynamic; +using System.Linq.Expressions; using System.Reflection; -using AstUtils = Microsoft.Scripting.Ast.Utils; + using Microsoft.Scripting.Actions.Calls; -using Microsoft.Scripting.Utils; + +using AstUtils = Microsoft.Scripting.Ast.Utils; namespace IronPython.Runtime.Binding { public sealed class SiteLocalStorageBuilder : ArgBuilder { - public SiteLocalStorageBuilder(ParameterInfo info) + public SiteLocalStorageBuilder(ParameterInfo info) : base(info) { } diff --git a/src/core/IronPython/Runtime/Binding/WarningInfo.cs b/src/core/IronPython/Runtime/Binding/WarningInfo.cs index b00e665c4..ff34f839a 100644 --- a/src/core/IronPython/Runtime/Binding/WarningInfo.cs +++ b/src/core/IronPython/Runtime/Binding/WarningInfo.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Dynamic; using System.Linq.Expressions; @@ -15,9 +17,9 @@ namespace IronPython.Runtime.Binding { internal class WarningInfo { private readonly string/*!*/ _message; private readonly PythonType/*!*/ _type; - private readonly Expression _condition; + private readonly Expression? _condition; - public WarningInfo(PythonType/*!*/ type, string/*!*/ message, Expression condition = null) { + public WarningInfo(PythonType/*!*/ type, string/*!*/ message, Expression? condition = null) { _message = message; _type = type; _condition = condition; @@ -25,7 +27,7 @@ public WarningInfo(PythonType/*!*/ type, string/*!*/ message, Expression conditi public DynamicMetaObject/*!*/ AddWarning(Expression/*!*/ codeContext, DynamicMetaObject/*!*/ result) { Expression warn = Expression.Call( - typeof(PythonOps).GetMethod(nameof(PythonOps.Warn)), + typeof(PythonOps).GetMethod(nameof(PythonOps.Warn))!, codeContext, AstUtils.Constant(_type), AstUtils.Constant(_message), diff --git a/src/core/IronPython/Runtime/CompareUtil.cs b/src/core/IronPython/Runtime/CompareUtil.cs index 5ecb25049..37d9fb2f8 100644 --- a/src/core/IronPython/Runtime/CompareUtil.cs +++ b/src/core/IronPython/Runtime/CompareUtil.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Collections.Generic; using System.Diagnostics; @@ -11,7 +13,7 @@ namespace IronPython.Runtime { internal class CompareUtil { [ThreadStatic] - private static Stack CmpStack; + private static Stack? CmpStack; internal static bool Check(object o) => CmpStack?.Contains(o) ?? false; @@ -27,13 +29,13 @@ internal static void Push(object o) { internal static void Pop(object o) { Debug.Assert(CmpStack != null && CmpStack.Count > 0); - Debug.Assert(CmpStack.Peek() == o); + Debug.Assert(CmpStack!.Peek() == o); CmpStack.Pop(); } internal static void Pop(object o1, object o2) { Debug.Assert(CmpStack != null && CmpStack.Count > 0); - Debug.Assert(CmpStack.Peek() is TwoObjects t && t.Equals(new TwoObjects(o1, o2))); + Debug.Assert(CmpStack!.Peek() is TwoObjects t && t.Equals(new TwoObjects(o1, o2))); CmpStack.Pop(); } @@ -55,7 +57,7 @@ public TwoObjects(object obj1, object obj2) { } public override int GetHashCode() => throw new NotSupportedException(); - public override bool Equals(object other) => other is TwoObjects o && o.obj1 == obj1 && o.obj2 == obj2; + public override bool Equals(object? other) => other is TwoObjects o && o.obj1 == obj1 && o.obj2 == obj2; } } } diff --git a/src/core/IronPython/Runtime/CompileFlags.cs b/src/core/IronPython/Runtime/CompileFlags.cs index b50bc0d75..4fb8a748f 100644 --- a/src/core/IronPython/Runtime/CompileFlags.cs +++ b/src/core/IronPython/Runtime/CompileFlags.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; namespace IronPython.Runtime { diff --git a/src/core/IronPython/Runtime/CompiledLoader.cs b/src/core/IronPython/Runtime/CompiledLoader.cs index 06f29cb3e..cf802eff5 100644 --- a/src/core/IronPython/Runtime/CompiledLoader.cs +++ b/src/core/IronPython/Runtime/CompiledLoader.cs @@ -2,14 +2,15 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Collections.Generic; using System.IO; -using Microsoft.Scripting; - using IronPython.Compiler; -using IronPython.Runtime.Operations; + +using Microsoft.Scripting; namespace IronPython.Runtime { public class CompiledLoader { @@ -30,11 +31,11 @@ internal void AddScriptCode(ScriptCode code) { } } - public ModuleLoader find_module(CodeContext/*!*/ context, string fullname, PythonList path = null) { - if (_codes.TryGetValue(fullname, out OnDiskScriptCode sc)) { + public ModuleLoader? find_module(CodeContext/*!*/ context, string fullname, PythonList? path = null) { + if (_codes.TryGetValue(fullname, out OnDiskScriptCode? sc)) { int sep = fullname.LastIndexOf('.'); string name = fullname; - string parentName = null; + string? parentName = null; if (sep != -1) { parentName = fullname.Substring(0, sep); name = fullname.Substring(sep + 1); diff --git a/src/core/IronPython/Runtime/DictionaryOps.cs b/src/core/IronPython/Runtime/DictionaryOps.cs index 6743aca33..868165ede 100644 --- a/src/core/IronPython/Runtime/DictionaryOps.cs +++ b/src/core/IronPython/Runtime/DictionaryOps.cs @@ -2,20 +2,18 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System; +#nullable enable + using System.Collections; using System.Collections.Generic; using System.Diagnostics; -using System.Runtime.CompilerServices; using System.Text; -using Microsoft.Scripting; -using Microsoft.Scripting.Runtime; - -using IronPython.Runtime.Binding; using IronPython.Runtime.Operations; using IronPython.Runtime.Types; +using Microsoft.Scripting.Runtime; + namespace IronPython.Runtime { /// /// Provides both helpers for implementing Python dictionaries as well @@ -29,8 +27,8 @@ public static class DictionaryOps { // Dictionary has an odd not-implemented check to support custom dictionaries and therefore // needs a custom __eq__ / __ne__ implementation. - public static string/*!*/ __repr__(CodeContext/*!*/ context, IDictionary self) { - List infinite = PythonOps.GetAndCheckInfinite(self); + public static string/*!*/ __repr__(CodeContext/*!*/ context, IDictionary self) { + List? infinite = PythonOps.GetAndCheckInfinite(self); if (infinite == null) { return "{...}"; } @@ -41,7 +39,7 @@ public static class DictionaryOps { StringBuilder buf = new StringBuilder(); buf.Append("{"); bool first = true; - foreach (KeyValuePair kv in self) { + foreach (KeyValuePair kv in self) { if (first) first = false; else buf.Append(", "); @@ -66,7 +64,7 @@ public static class DictionaryOps { } } - public static object get(PythonDictionary self, object key, object defaultValue = null) { + public static object? get(PythonDictionary self, object key, object? defaultValue = null) { if (self.TryGetValueNoMissing(key, out object ret)) return ret; return defaultValue; } @@ -110,11 +108,11 @@ public static PythonTuple popitem(PythonDictionary self) { throw PythonOps.KeyError("dictionary is empty"); } - public static object setdefault(PythonDictionary self, object key) { + public static object? setdefault(PythonDictionary self, object key) { return setdefault(self, key, null); } - public static object setdefault(PythonDictionary self, object key, object defaultValue) { + public static object? setdefault(PythonDictionary self, object key, object? defaultValue) { if (self.TryGetValueNoMissing(key, out object ret)) return ret; self.SetItem(key, defaultValue); return defaultValue; @@ -136,7 +134,7 @@ private static void SlowUpdate(CodeContext/*!*/ context, PythonDictionary/*!*/ s while (e.MoveNext()) { self._storage.Add(ref self._storage, e.Key, e.Value); } - } else if (PythonOps.TryGetBoundAttr(other, "keys", out object keysFunc)) { + } else if (PythonOps.TryGetBoundAttr(other, "keys", out object? keysFunc)) { // user defined dictionary IEnumerator i = PythonOps.GetEnumerator(context, PythonCalls.Call(context, keysFunc)); while (i.MoveNext()) { @@ -160,9 +158,8 @@ private static void SlowUpdate(CodeContext/*!*/ context, PythonDictionary/*!*/ s #region Dictionary Helper APIs - internal static bool TryGetValueVirtual(CodeContext context, PythonDictionary self, object key, ref object DefaultGetItem, out object value) { + internal static bool TryGetValueVirtual(CodeContext context, PythonDictionary self, object key, ref object DefaultGetItem, out object? value) { if (self is IPythonObject sdo) { - Debug.Assert(sdo != null); PythonType myType = sdo.PythonType; PythonTypeSlot dts; diff --git a/src/core/IronPython/Runtime/DictionaryTypeInfoAttribute.cs b/src/core/IronPython/Runtime/DictionaryTypeInfoAttribute.cs index 583d8269c..5e5604573 100644 --- a/src/core/IronPython/Runtime/DictionaryTypeInfoAttribute.cs +++ b/src/core/IronPython/Runtime/DictionaryTypeInfoAttribute.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; namespace IronPython.Runtime { diff --git a/src/core/IronPython/Runtime/DontMapGetMemberNamesToDirAttribute.cs b/src/core/IronPython/Runtime/DontMapGetMemberNamesToDirAttribute.cs index ca2bcef7d..6b24f9913 100644 --- a/src/core/IronPython/Runtime/DontMapGetMemberNamesToDirAttribute.cs +++ b/src/core/IronPython/Runtime/DontMapGetMemberNamesToDirAttribute.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; namespace IronPython.Runtime { diff --git a/src/core/IronPython/Runtime/DontMapICollectionToLenAttribute.cs b/src/core/IronPython/Runtime/DontMapICollectionToLenAttribute.cs index e279eb2f4..eda64b413 100644 --- a/src/core/IronPython/Runtime/DontMapICollectionToLenAttribute.cs +++ b/src/core/IronPython/Runtime/DontMapICollectionToLenAttribute.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; namespace IronPython.Runtime { diff --git a/src/core/IronPython/Runtime/DontMapIDisposableToContextManagerAttribute.cs b/src/core/IronPython/Runtime/DontMapIDisposableToContextManagerAttribute.cs index 70e7744c7..f0230c847 100644 --- a/src/core/IronPython/Runtime/DontMapIDisposableToContextManagerAttribute.cs +++ b/src/core/IronPython/Runtime/DontMapIDisposableToContextManagerAttribute.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; namespace IronPython.Runtime { diff --git a/src/core/IronPython/Runtime/DontMapIEnumerableToContainsAttribute.cs b/src/core/IronPython/Runtime/DontMapIEnumerableToContainsAttribute.cs index d2c362f2a..b2546c4cd 100644 --- a/src/core/IronPython/Runtime/DontMapIEnumerableToContainsAttribute.cs +++ b/src/core/IronPython/Runtime/DontMapIEnumerableToContainsAttribute.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; namespace IronPython.Runtime { diff --git a/src/core/IronPython/Runtime/DontMapIEnumerableToIterAttribute.cs b/src/core/IronPython/Runtime/DontMapIEnumerableToIterAttribute.cs index bf608ab22..c75cd7684 100644 --- a/src/core/IronPython/Runtime/DontMapIEnumerableToIterAttribute.cs +++ b/src/core/IronPython/Runtime/DontMapIEnumerableToIterAttribute.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; namespace IronPython.Runtime { diff --git a/src/core/IronPython/Runtime/ErrorCodes.cs b/src/core/IronPython/Runtime/ErrorCodes.cs index 3718dcf28..be3457707 100644 --- a/src/core/IronPython/Runtime/ErrorCodes.cs +++ b/src/core/IronPython/Runtime/ErrorCodes.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + namespace IronPython.Runtime { public static class ErrorCodes { // The error flags diff --git a/src/core/IronPython/Runtime/Exceptions/AttributeErrorException.cs b/src/core/IronPython/Runtime/Exceptions/AttributeErrorException.cs index ec4a18038..3af1e3bd3 100644 --- a/src/core/IronPython/Runtime/Exceptions/AttributeErrorException.cs +++ b/src/core/IronPython/Runtime/Exceptions/AttributeErrorException.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Collections.Generic; using System.Runtime.Serialization; @@ -13,12 +15,11 @@ namespace IronPython.Runtime.Exceptions { // *** BEGIN GENERATED CODE *** // generated by function: gen_one_exception_specialized from: generate_exceptions.py - [Serializable] public class AttributeErrorException : MissingMemberException, IPythonAwareException { - private PythonExceptions.BaseException _pyExceptionObject; - private List _frames; - private TraceBack _traceback; + private PythonExceptions.BaseException? _pyExceptionObject; + private List? _frames; + private TraceBack? _traceback; public AttributeErrorException() : base() { } public AttributeErrorException(string msg) : base(msg) { } @@ -36,23 +37,22 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont } #endif - PythonExceptions.BaseException IPythonAwareException.PythonException { + PythonExceptions.BaseException? IPythonAwareException.PythonException { get { return _pyExceptionObject; } set { _pyExceptionObject = value; } } - List IPythonAwareException.Frames { + List? IPythonAwareException.Frames { get { return _frames; } set { _frames = value; } } - TraceBack IPythonAwareException.TraceBack { + TraceBack? IPythonAwareException.TraceBack { get { return _traceback; } set { _traceback = value; } } } - // *** END GENERATED CODE *** #endregion diff --git a/src/core/IronPython/Runtime/Exceptions/GeneratorExitException.cs b/src/core/IronPython/Runtime/Exceptions/GeneratorExitException.cs index 9a0a1e7b9..6a08b5e63 100644 --- a/src/core/IronPython/Runtime/Exceptions/GeneratorExitException.cs +++ b/src/core/IronPython/Runtime/Exceptions/GeneratorExitException.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Runtime.Serialization; diff --git a/src/core/IronPython/Runtime/Exceptions/IndentationException.cs b/src/core/IronPython/Runtime/Exceptions/IndentationException.cs index 508522cb0..843f12098 100644 --- a/src/core/IronPython/Runtime/Exceptions/IndentationException.cs +++ b/src/core/IronPython/Runtime/Exceptions/IndentationException.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Runtime.Serialization; using System.Security; diff --git a/src/core/IronPython/Runtime/Exceptions/TabException.cs b/src/core/IronPython/Runtime/Exceptions/TabException.cs index 7d0815d86..48fb234a7 100644 --- a/src/core/IronPython/Runtime/Exceptions/TabException.cs +++ b/src/core/IronPython/Runtime/Exceptions/TabException.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Dynamic; using Microsoft.Scripting; diff --git a/src/core/IronPython/Runtime/Exceptions/ValueErrorException.cs b/src/core/IronPython/Runtime/Exceptions/ValueErrorException.cs index 9b86c8201..e02ba932c 100644 --- a/src/core/IronPython/Runtime/Exceptions/ValueErrorException.cs +++ b/src/core/IronPython/Runtime/Exceptions/ValueErrorException.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Collections.Generic; using System.Runtime.Serialization; @@ -16,9 +18,9 @@ namespace IronPython.Runtime.Exceptions { [Serializable] public class ValueErrorException : ArgumentException, IPythonAwareException { - private PythonExceptions.BaseException _pyExceptionObject; - private List _frames; - private TraceBack _traceback; + private PythonExceptions.BaseException? _pyExceptionObject; + private List? _frames; + private TraceBack? _traceback; public ValueErrorException() : base() { } public ValueErrorException(string msg) : base(msg) { } @@ -36,23 +38,22 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont } #endif - PythonExceptions.BaseException IPythonAwareException.PythonException { + PythonExceptions.BaseException? IPythonAwareException.PythonException { get { return _pyExceptionObject; } set { _pyExceptionObject = value; } } - List IPythonAwareException.Frames { + List? IPythonAwareException.Frames { get { return _frames; } set { _frames = value; } } - TraceBack IPythonAwareException.TraceBack { + TraceBack? IPythonAwareException.TraceBack { get { return _traceback; } set { _traceback = value; } } } - // *** END GENERATED CODE *** #endregion diff --git a/src/core/IronPython/Runtime/FunctionAttributes.cs b/src/core/IronPython/Runtime/FunctionAttributes.cs index 6ffc0c85b..45edf190e 100644 --- a/src/core/IronPython/Runtime/FunctionAttributes.cs +++ b/src/core/IronPython/Runtime/FunctionAttributes.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; namespace IronPython.Runtime { diff --git a/src/core/IronPython/Runtime/IParameterSequence.cs b/src/core/IronPython/Runtime/IParameterSequence.cs index 2224109f4..7de27da16 100644 --- a/src/core/IronPython/Runtime/IParameterSequence.cs +++ b/src/core/IronPython/Runtime/IParameterSequence.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + namespace IronPython.Runtime { /// /// Represents a sequence which may have been provided as a set of parameters to an indexer. diff --git a/src/core/IronPython/Runtime/Implementation.cs b/src/core/IronPython/Runtime/Implementation.cs index cc244460f..5d875f844 100644 --- a/src/core/IronPython/Runtime/Implementation.cs +++ b/src/core/IronPython/Runtime/Implementation.cs @@ -2,12 +2,11 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; -using System.Linq; using System.Reflection; -using IronPython.Runtime.Operations; - namespace IronPython.Runtime { [PythonType("sys.version_info")] public class VersionInfo : PythonTuple { @@ -98,12 +97,12 @@ static string GetShortReleaseLevel(string releaselevel) { static CurrentVersion() { var assembly = typeof(CurrentVersion).Assembly; - var version = new AssemblyName(assembly.FullName).Version; // don't use Assembly.GetName since it fails in partial trust scenarios + var version = new AssemblyName(assembly.FullName!).Version!; // don't use Assembly.GetName since it fails in partial trust scenarios Major = version.Major; Minor = version.Minor; Micro = version.Build; Series = version.ToString(2); - var split = assembly.GetCustomAttribute().InformationalVersion.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + var split = assembly.GetCustomAttribute()!.InformationalVersion.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); ReleaseLevel = split[split.Length - 2]; ReleaseSerial = int.Parse(split[split.Length - 1]); DisplayName = $"IronPython {GetVersionString(Major, Minor, Micro, ReleaseLevel, ReleaseSerial)}"; diff --git a/src/core/IronPython/Runtime/InstancedModuleDictionaryStorage.cs b/src/core/IronPython/Runtime/InstancedModuleDictionaryStorage.cs index d1682025c..93cedcf97 100644 --- a/src/core/IronPython/Runtime/InstancedModuleDictionaryStorage.cs +++ b/src/core/IronPython/Runtime/InstancedModuleDictionaryStorage.cs @@ -2,8 +2,10 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System; +#nullable enable + using System.Collections.Generic; + using IronPython.Compiler; namespace IronPython.Runtime { diff --git a/src/core/IronPython/Runtime/KwCallInfo.cs b/src/core/IronPython/Runtime/KwCallInfo.cs index a3a8afa11..cf9f72973 100644 --- a/src/core/IronPython/Runtime/KwCallInfo.cs +++ b/src/core/IronPython/Runtime/KwCallInfo.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + namespace IronPython.Runtime { public sealed class KwCallInfo { private readonly object[] _args; diff --git a/src/core/IronPython/Runtime/MaybeNotImplementedAttribute.cs b/src/core/IronPython/Runtime/MaybeNotImplementedAttribute.cs index 274d65e90..19a57aced 100644 --- a/src/core/IronPython/Runtime/MaybeNotImplementedAttribute.cs +++ b/src/core/IronPython/Runtime/MaybeNotImplementedAttribute.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; namespace IronPython.Runtime { diff --git a/src/core/IronPython/Runtime/MemoryStreamContentProvider.cs b/src/core/IronPython/Runtime/MemoryStreamContentProvider.cs index 4fd4e5704..17111b2e8 100644 --- a/src/core/IronPython/Runtime/MemoryStreamContentProvider.cs +++ b/src/core/IronPython/Runtime/MemoryStreamContentProvider.cs @@ -2,8 +2,11 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.IO; + using Microsoft.Scripting; using Microsoft.Scripting.Utils; diff --git a/src/core/IronPython/Runtime/MissingParameter.cs b/src/core/IronPython/Runtime/MissingParameter.cs index 0c3fbc104..be5e3f350 100644 --- a/src/core/IronPython/Runtime/MissingParameter.cs +++ b/src/core/IronPython/Runtime/MissingParameter.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + namespace IronPython.Runtime { public sealed class MissingParameter { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")] diff --git a/src/core/IronPython/Runtime/ModuleGlobalCache.cs b/src/core/IronPython/Runtime/ModuleGlobalCache.cs index f6c55203a..9ce7bfc95 100644 --- a/src/core/IronPython/Runtime/ModuleGlobalCache.cs +++ b/src/core/IronPython/Runtime/ModuleGlobalCache.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Diagnostics; diff --git a/src/core/IronPython/Runtime/ModuleLoader.cs b/src/core/IronPython/Runtime/ModuleLoader.cs index 3966d0157..82e91780d 100644 --- a/src/core/IronPython/Runtime/ModuleLoader.cs +++ b/src/core/IronPython/Runtime/ModuleLoader.cs @@ -2,17 +2,18 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System; -using Microsoft.Scripting; +#nullable enable + using IronPython.Compiler; namespace IronPython.Runtime { public sealed class ModuleLoader { private readonly OnDiskScriptCode _sc; - private readonly string _parentName, _name; + private readonly string? _parentName; + private readonly string _name; - internal ModuleLoader(OnDiskScriptCode sc, string parentName, string name) { + internal ModuleLoader(OnDiskScriptCode sc, string? parentName, string name) { _sc = sc; _parentName = parentName; _name = name; @@ -27,7 +28,7 @@ public PythonModule load_module(CodeContext/*!*/ context, string fullName) { if (_parentName != null) { // if we are a module in a package update the parent package w/ our scope. - object parent; + object? parent; if (pc.SystemStateModules.TryGetValue(_parentName, out parent)) { if (parent is PythonModule s) { s.__dict__[_name] = newContext.ModuleContext.Module; @@ -38,5 +39,4 @@ public PythonModule load_module(CodeContext/*!*/ context, string fullName) { return newContext.ModuleContext.Module; } } - } diff --git a/src/core/IronPython/Runtime/ModuleOptions.cs b/src/core/IronPython/Runtime/ModuleOptions.cs index 9d051028c..a49939153 100644 --- a/src/core/IronPython/Runtime/ModuleOptions.cs +++ b/src/core/IronPython/Runtime/ModuleOptions.cs @@ -2,9 +2,9 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; -using System.Collections.Generic; -using System.Text; namespace IronPython.Runtime { [Flags] diff --git a/src/core/IronPython/Runtime/NameType.cs b/src/core/IronPython/Runtime/NameType.cs index 1427d6773..5f93ccc62 100644 --- a/src/core/IronPython/Runtime/NameType.cs +++ b/src/core/IronPython/Runtime/NameType.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; namespace IronPython.Runtime { diff --git a/src/core/IronPython/Runtime/Operations/BoolOps.cs b/src/core/IronPython/Runtime/Operations/BoolOps.cs index 9654968e3..2e72c603f 100644 --- a/src/core/IronPython/Runtime/Operations/BoolOps.cs +++ b/src/core/IronPython/Runtime/Operations/BoolOps.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Numerics; diff --git a/src/core/IronPython/Runtime/Operations/FloatOps.Generated.cs b/src/core/IronPython/Runtime/Operations/FloatOps.Generated.cs index 113d646c0..bd670bac3 100644 --- a/src/core/IronPython/Runtime/Operations/FloatOps.Generated.cs +++ b/src/core/IronPython/Runtime/Operations/FloatOps.Generated.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Numerics; using System.Runtime.CompilerServices; diff --git a/src/core/IronPython/Runtime/Operations/FloatOps.cs b/src/core/IronPython/Runtime/Operations/FloatOps.cs index 61df44832..51cf840ea 100644 --- a/src/core/IronPython/Runtime/Operations/FloatOps.cs +++ b/src/core/IronPython/Runtime/Operations/FloatOps.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Diagnostics; using System.Globalization; @@ -21,7 +23,7 @@ namespace IronPython.Runtime.Operations { public static partial class DoubleOps { - private static Regex _fromHexRegex; + private static Regex? _fromHexRegex; [StaticExtensionMethod] public static object __new__(CodeContext/*!*/ context, PythonType cls) { @@ -67,7 +69,7 @@ public static object __new__(CodeContext/*!*/ context, PythonType cls, object x) } } - internal static bool TryToFloat(CodeContext context, object/*?*/ value, out double result) { + internal static bool TryToFloat(CodeContext context, object? value, out double result) { if (value is double d) { result = d; } else if (value is int i) { @@ -80,7 +82,7 @@ internal static bool TryToFloat(CodeContext context, object/*?*/ value, out doub result = ed.Value; } else if (value is Extensible ebi) { result = BigIntegerOps.ToDouble(ebi.Value); - } else if (PythonOps.TryToIndex(value, out object ireal)) { // Python 3.8: fall back on __index__ + } else if (PythonOps.TryToIndex(value, out object? ireal)) { // Python 3.8: fall back on __index__ result = ireal switch { int ii => ii, BigInteger bii => BigIntegerOps.ToDouble(bii), @@ -91,7 +93,7 @@ internal static bool TryToFloat(CodeContext context, object/*?*/ value, out doub } return true; - static bool TryInvokeFloat(CodeContext context, object/*?*/ o, out double result) { + static bool TryInvokeFloat(CodeContext context, object? o, out double result) { if (PythonTypeOps.TryInvokeUnaryOperator(context, o, "__float__", out object retobj)) { switch (retobj) { case double d: @@ -208,7 +210,7 @@ public static object fromhex(CodeContext/*!*/ context, PythonType/*!*/ cls, stri return zeroRes; } - return PythonCalls.Call(cls, zeroRes); + return PythonCalls.Call(cls, zeroRes)!; } // integer value is too big, no way we're fitting this in. throw HexStringOverflow(); @@ -313,7 +315,7 @@ public static object fromhex(CodeContext/*!*/ context, PythonType/*!*/ cls, stri return res; } - return PythonCalls.Call(cls, res); + return PythonCalls.Call(cls, res)!; } private static double? TryParseSpecialFloat(string self) { diff --git a/src/core/IronPython/Runtime/Operations/IntOps.Generated.cs b/src/core/IronPython/Runtime/Operations/IntOps.Generated.cs index 4a6c512df..071e22a63 100644 --- a/src/core/IronPython/Runtime/Operations/IntOps.Generated.cs +++ b/src/core/IronPython/Runtime/Operations/IntOps.Generated.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Globalization; using System.Numerics; diff --git a/src/core/IronPython/Runtime/Operations/MarshalOps.cs b/src/core/IronPython/Runtime/Operations/MarshalOps.cs index 5c043c803..5ccfa6213 100644 --- a/src/core/IronPython/Runtime/Operations/MarshalOps.cs +++ b/src/core/IronPython/Runtime/Operations/MarshalOps.cs @@ -1,4 +1,8 @@ -using System; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +using System; using System.Collections.Generic; using System.Globalization; using System.Numerics; diff --git a/src/core/IronPython/Runtime/Operations/PythonOps.Generated.cs b/src/core/IronPython/Runtime/Operations/PythonOps.Generated.cs index 016dcc6dd..44b377549 100644 --- a/src/core/IronPython/Runtime/Operations/PythonOps.Generated.cs +++ b/src/core/IronPython/Runtime/Operations/PythonOps.Generated.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.ComponentModel; @@ -15,147 +17,147 @@ public static partial class PythonOps { // generated by function: factory_gen from: generate_exceptions.py - public static Exception ImportError(string format, params object[] args) { + public static Exception ImportError(string format, params object?[] args) { return new ImportException(string.Format(format, args)); } - public static Exception RuntimeError(string format, params object[] args) { + public static Exception RuntimeError(string format, params object?[] args) { return new RuntimeException(string.Format(format, args)); } - public static Exception UnicodeTranslateError(string format, params object[] args) { + public static Exception UnicodeTranslateError(string format, params object?[] args) { return new UnicodeTranslateException(string.Format(format, args)); } - public static Exception PendingDeprecationWarning(string format, params object[] args) { + public static Exception PendingDeprecationWarning(string format, params object?[] args) { return new PendingDeprecationWarningException(string.Format(format, args)); } - public static Exception LookupError(string format, params object[] args) { + public static Exception LookupError(string format, params object?[] args) { return new LookupException(string.Format(format, args)); } - public static Exception OSError(string format, params object[] args) { + public static Exception OSError(string format, params object?[] args) { return new OSException(string.Format(format, args)); } - public static Exception DeprecationWarning(string format, params object[] args) { + public static Exception DeprecationWarning(string format, params object?[] args) { return new DeprecationWarningException(string.Format(format, args)); } - public static Exception UnicodeError(string format, params object[] args) { + public static Exception UnicodeError(string format, params object?[] args) { return new UnicodeException(string.Format(format, args)); } - public static Exception FloatingPointError(string format, params object[] args) { + public static Exception FloatingPointError(string format, params object?[] args) { return new FloatingPointException(string.Format(format, args)); } - public static Exception ReferenceError(string format, params object[] args) { + public static Exception ReferenceError(string format, params object?[] args) { return new ReferenceException(string.Format(format, args)); } - public static Exception FutureWarning(string format, params object[] args) { + public static Exception FutureWarning(string format, params object?[] args) { return new FutureWarningException(string.Format(format, args)); } - public static Exception AssertionError(string format, params object[] args) { + public static Exception AssertionError(string format, params object?[] args) { return new AssertionException(string.Format(format, args)); } - public static Exception RuntimeWarning(string format, params object[] args) { + public static Exception RuntimeWarning(string format, params object?[] args) { return new RuntimeWarningException(string.Format(format, args)); } - public static Exception ImportWarning(string format, params object[] args) { + public static Exception ImportWarning(string format, params object?[] args) { return new ImportWarningException(string.Format(format, args)); } - public static Exception UserWarning(string format, params object[] args) { + public static Exception UserWarning(string format, params object?[] args) { return new UserWarningException(string.Format(format, args)); } - public static Exception SyntaxWarning(string format, params object[] args) { + public static Exception SyntaxWarning(string format, params object?[] args) { return new SyntaxWarningException(string.Format(format, args)); } - public static Exception UnicodeWarning(string format, params object[] args) { + public static Exception UnicodeWarning(string format, params object?[] args) { return new UnicodeWarningException(string.Format(format, args)); } - public static Exception StopIteration(string format, params object[] args) { + public static Exception StopIteration(string format, params object?[] args) { return new StopIterationException(string.Format(format, args)); } - public static Exception BytesWarning(string format, params object[] args) { + public static Exception BytesWarning(string format, params object?[] args) { return new BytesWarningException(string.Format(format, args)); } - public static Exception BufferError(string format, params object[] args) { + public static Exception BufferError(string format, params object?[] args) { return new BufferException(string.Format(format, args)); } - public static Exception ResourceWarning(string format, params object[] args) { + public static Exception ResourceWarning(string format, params object?[] args) { return new ResourceWarningException(string.Format(format, args)); } - public static Exception FileExistsError(string format, params object[] args) { + public static Exception FileExistsError(string format, params object?[] args) { return new FileExistsException(string.Format(format, args)); } - public static Exception BlockingIOError(string format, params object[] args) { + public static Exception BlockingIOError(string format, params object?[] args) { return new BlockingIOException(string.Format(format, args)); } - public static Exception NotADirectoryError(string format, params object[] args) { + public static Exception NotADirectoryError(string format, params object?[] args) { return new NotADirectoryException(string.Format(format, args)); } - public static Exception InterruptedError(string format, params object[] args) { + public static Exception InterruptedError(string format, params object?[] args) { return new InterruptedException(string.Format(format, args)); } - public static Exception ChildProcessError(string format, params object[] args) { + public static Exception ChildProcessError(string format, params object?[] args) { return new ChildProcessException(string.Format(format, args)); } - public static Exception IsADirectoryError(string format, params object[] args) { + public static Exception IsADirectoryError(string format, params object?[] args) { return new IsADirectoryException(string.Format(format, args)); } - public static Exception ProcessLookupError(string format, params object[] args) { + public static Exception ProcessLookupError(string format, params object?[] args) { return new ProcessLookupException(string.Format(format, args)); } - public static Exception ConnectionError(string format, params object[] args) { + public static Exception ConnectionError(string format, params object?[] args) { return new ConnectionException(string.Format(format, args)); } - public static Exception ConnectionAbortedError(string format, params object[] args) { + public static Exception ConnectionAbortedError(string format, params object?[] args) { return new ConnectionAbortedException(string.Format(format, args)); } - public static Exception BrokenPipeError(string format, params object[] args) { + public static Exception BrokenPipeError(string format, params object?[] args) { return new BrokenPipeException(string.Format(format, args)); } - public static Exception ConnectionRefusedError(string format, params object[] args) { + public static Exception ConnectionRefusedError(string format, params object?[] args) { return new ConnectionRefusedException(string.Format(format, args)); } - public static Exception ConnectionResetError(string format, params object[] args) { + public static Exception ConnectionResetError(string format, params object?[] args) { return new ConnectionResetException(string.Format(format, args)); } - public static Exception RecursionError(string format, params object[] args) { + public static Exception RecursionError(string format, params object?[] args) { return new RecursionException(string.Format(format, args)); } - public static Exception StopAsyncIteration(string format, params object[] args) { + public static Exception StopAsyncIteration(string format, params object?[] args) { return new StopAsyncIterationException(string.Format(format, args)); } - public static Exception ModuleNotFoundError(string format, params object[] args) { + public static Exception ModuleNotFoundError(string format, params object?[] args) { return new ModuleNotFoundException(string.Format(format, args)); } diff --git a/src/core/IronPython/Runtime/PlatformsAttribute.cs b/src/core/IronPython/Runtime/PlatformsAttribute.cs index c8c8c5789..11d2910fe 100644 --- a/src/core/IronPython/Runtime/PlatformsAttribute.cs +++ b/src/core/IronPython/Runtime/PlatformsAttribute.cs @@ -2,7 +2,10 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace IronPython.Runtime { @@ -23,9 +26,9 @@ public enum PlatformFamily { public static readonly PlatformID[] WindowsFamily = { PlatformID.Win32NT, PlatformID.Win32S, PlatformID.Win32Windows, PlatformID.WinCE, PlatformID.Xbox }; public static readonly PlatformID[] UnixFamily = { PlatformID.MacOSX, PlatformID.Unix }; - public PlatformID[] ValidPlatforms { get; protected set; } + public PlatformID[] ValidPlatforms { get; protected set; } = []; - public bool IsPlatformValid => ValidPlatforms == null || ValidPlatforms.Length == 0 || Array.IndexOf(ValidPlatforms, ActualPlatform) >= 0; + public bool IsPlatformValid => ValidPlatforms.Length == 0 || Array.IndexOf(ValidPlatforms, ActualPlatform) >= 0; private static PlatformID ActualPlatform => RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? PlatformID.Unix : @@ -43,4 +46,4 @@ protected void SetValidPlatforms(PlatformFamily validPlatformFamily) { } } } -} \ No newline at end of file +} diff --git a/src/core/IronPython/Runtime/Profiler.cs b/src/core/IronPython/Runtime/Profiler.cs index bc0d245e4..022282087 100644 --- a/src/core/IronPython/Runtime/Profiler.cs +++ b/src/core/IronPython/Runtime/Profiler.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using MSAst = System.Linq.Expressions; using System; @@ -222,7 +224,7 @@ internal MSAst.Expression AddOuterProfiling(MSAst.Expression/*!*/ body, MSAst.Pa tick, Ast.Call( Ast.Constant(this, typeof(Profiler)), - typeof(Profiler).GetMethod(nameof(Profiler.StartCall)), + typeof(Profiler).GetMethod(nameof(Profiler.StartCall))!, AstUtils.Constant(profileIndex) ) ), @@ -231,7 +233,7 @@ internal MSAst.Expression AddOuterProfiling(MSAst.Expression/*!*/ body, MSAst.Pa ).Finally( Ast.Call( Ast.Constant(this, typeof(Profiler)), - typeof(Profiler).GetMethod(nameof(Profiler.FinishCall)), + typeof(Profiler).GetMethod(nameof(Profiler.FinishCall))!, AstUtils.Constant(profileIndex), tick ) @@ -245,7 +247,7 @@ internal MSAst.Expression AddInnerProfiling(MSAst.Expression/*!*/ body, MSAst.Pa tick, Ast.Call( Ast.Constant(this, typeof(Profiler)), - typeof(Profiler).GetMethod(nameof(Profiler.StartNestedCall)), + typeof(Profiler).GetMethod(nameof(Profiler.StartNestedCall))!, AstUtils.Constant(profileIndex), tick ) @@ -257,7 +259,7 @@ internal MSAst.Expression AddInnerProfiling(MSAst.Expression/*!*/ body, MSAst.Pa tick, Ast.Call( Ast.Constant(this, typeof(Profiler)), - typeof(Profiler).GetMethod(nameof(Profiler.FinishNestedCall)), + typeof(Profiler).GetMethod(nameof(Profiler.FinishNestedCall))!, AstUtils.Constant(profileIndex), tick ) diff --git a/src/core/IronPython/Runtime/PythonContext.Generated.cs b/src/core/IronPython/Runtime/PythonContext.Generated.cs index 9942356bc..5398e7bef 100644 --- a/src/core/IronPython/Runtime/PythonContext.Generated.cs +++ b/src/core/IronPython/Runtime/PythonContext.Generated.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Runtime.CompilerServices; using System.Threading; diff --git a/src/core/IronPython/Runtime/PythonDocumentationProvider.cs b/src/core/IronPython/Runtime/PythonDocumentationProvider.cs index adc89c53b..e668848bd 100644 --- a/src/core/IronPython/Runtime/PythonDocumentationProvider.cs +++ b/src/core/IronPython/Runtime/PythonDocumentationProvider.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Collections.Generic; using System.Reflection; @@ -84,8 +86,7 @@ private static MemberDoc MakeMemberDoc(string name, object value, bool fromClass kind = fromClass ? MemberKind.Method : MemberKind.Function; } else if (value is BuiltinMethodDescriptor || value is Method) { kind = MemberKind.Method; - } else if (value is PythonType) { - var pt = value as PythonType; + } else if (value is PythonType pt) { if (pt.IsSystemType && pt.UnderlyingSystemType.IsEnum) { kind = MemberKind.Enum; } else { diff --git a/src/core/IronPython/Runtime/PythonHiddenAttribute.cs b/src/core/IronPython/Runtime/PythonHiddenAttribute.cs index f9d8d0453..0773ee0a8 100644 --- a/src/core/IronPython/Runtime/PythonHiddenAttribute.cs +++ b/src/core/IronPython/Runtime/PythonHiddenAttribute.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Reflection; diff --git a/src/core/IronPython/Runtime/PythonHiddenBaseClassAttribute.cs b/src/core/IronPython/Runtime/PythonHiddenBaseClassAttribute.cs index 30cd90a43..989b46685 100644 --- a/src/core/IronPython/Runtime/PythonHiddenBaseClassAttribute.cs +++ b/src/core/IronPython/Runtime/PythonHiddenBaseClassAttribute.cs @@ -1,7 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +#nullable enable + +using System; namespace IronPython.Runtime { /// diff --git a/src/core/IronPython/Runtime/PythonModuleAttribute.cs b/src/core/IronPython/Runtime/PythonModuleAttribute.cs index 8a4be79e8..8e89c149a 100644 --- a/src/core/IronPython/Runtime/PythonModuleAttribute.cs +++ b/src/core/IronPython/Runtime/PythonModuleAttribute.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using Microsoft.Scripting.Utils; diff --git a/src/core/IronPython/Runtime/PythonNarrowing.cs b/src/core/IronPython/Runtime/PythonNarrowing.cs index 064229482..7604b3370 100644 --- a/src/core/IronPython/Runtime/PythonNarrowing.cs +++ b/src/core/IronPython/Runtime/PythonNarrowing.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using Microsoft.Scripting.Actions.Calls; namespace IronPython.Runtime { diff --git a/src/core/IronPython/Runtime/PythonOptions.cs b/src/core/IronPython/Runtime/PythonOptions.cs index 92125273f..d5dc14385 100644 --- a/src/core/IronPython/Runtime/PythonOptions.cs +++ b/src/core/IronPython/Runtime/PythonOptions.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -123,7 +125,7 @@ public sealed class PythonOptions : LanguageOptions { /// /// Returns a regular expression of Python files which should not be emitted in debug mode. /// - public Regex NoDebug { get; } + public Regex? NoDebug { get; } public bool Quiet { get; } @@ -138,7 +140,7 @@ public PythonOptions() : this(null) { } - public PythonOptions(IDictionary options) + public PythonOptions(IDictionary? options) : base(EnsureSearchPaths(options)) { Arguments = GetStringCollectionOption(options, "Arguments") ?? EmptyStringCollection; @@ -160,7 +162,7 @@ public PythonOptions(IDictionary options) Frames = FullFrames || GetOption(options, "Frames", true); GCStress = GetOption(options, "GCStress", null); Tracing = GetOption(options, "Tracing", false); - NoDebug = GetOption(options, "NoDebug", (Regex)null); + NoDebug = GetOption(options, "NoDebug", (Regex?)null); Quiet = GetOption(options, "Quiet", false); NoImportLib = GetOption(options, "NoImportLib", false); Isolated = GetOption(options, "Isolated", false); @@ -168,7 +170,7 @@ public PythonOptions(IDictionary options) ConsoleSupportLevel = GetEnumOption(options, "ConsoleSupportLevel", SharedIO.SupportLevel.Full); } - private static IDictionary EnsureSearchPaths(IDictionary options) { + private static IDictionary EnsureSearchPaths(IDictionary? options) { if (options == null) { return new Dictionary() { { "SearchPaths", new[] { "." } } }; } else if (!options.ContainsKey("SearchPaths")) { @@ -177,8 +179,8 @@ private static IDictionary EnsureSearchPaths(IDictionary(IDictionary options, string name, T defaultValue) where T : struct, Enum { - if (options != null && options.TryGetValue(name, out object value)) { + private static T GetEnumOption(IDictionary? options, string name, T defaultValue) where T : struct, Enum { + if (options != null && options.TryGetValue(name, out object? value)) { if (value is T variable) { return variable; } diff --git a/src/core/IronPython/Runtime/PythonScopeExtension.cs b/src/core/IronPython/Runtime/PythonScopeExtension.cs index 3adb330b5..ab7b47ec4 100644 --- a/src/core/IronPython/Runtime/PythonScopeExtension.cs +++ b/src/core/IronPython/Runtime/PythonScopeExtension.cs @@ -2,8 +2,10 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System; +#nullable enable + using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Threading; using Microsoft.Scripting.Runtime; @@ -18,7 +20,7 @@ namespace IronPython.Runtime { internal class PythonScopeExtension : ScopeExtension { private readonly ModuleContext _modContext; private readonly PythonModule _module; - private Dictionary _objectKeys; + private Dictionary? _objectKeys; public PythonScopeExtension(PythonContext context, Scope scope) : base(scope) { _module = new PythonModule(context, scope); @@ -43,6 +45,7 @@ public PythonModule Module { } } + [MemberNotNull(nameof(_objectKeys))] public Dictionary EnsureObjectKeys() { if (_objectKeys == null) { Interlocked.CompareExchange(ref _objectKeys, new Dictionary(), null); @@ -51,7 +54,7 @@ public Dictionary EnsureObjectKeys() { return _objectKeys; } - public Dictionary ObjectKeys { + public Dictionary? ObjectKeys { get { return _objectKeys; } diff --git a/src/core/IronPython/Runtime/Symbols.Generated.cs b/src/core/IronPython/Runtime/Symbols.Generated.cs index 12201afcf..5753aa93a 100644 --- a/src/core/IronPython/Runtime/Symbols.Generated.cs +++ b/src/core/IronPython/Runtime/Symbols.Generated.cs @@ -2,10 +2,11 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; + using IronPython.Runtime.Binding; -using Microsoft.Scripting; -using Microsoft.Scripting.Generation; namespace IronPython.Runtime { public static partial class Symbols { @@ -96,7 +97,6 @@ internal static string OperatorToReversedSymbol(PythonOperationKind op) { } } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] internal static PythonOperationKind OperatorToReverseOperator(PythonOperationKind op) { switch (op) { @@ -115,6 +115,5 @@ internal static PythonOperationKind OperatorToReverseOperator(PythonOperationKin return op | PythonOperationKind.Reversed; } } - } } diff --git a/src/core/IronPython/Runtime/ThrowingErrorSink.cs b/src/core/IronPython/Runtime/ThrowingErrorSink.cs index a2ea488f0..c2200682b 100644 --- a/src/core/IronPython/Runtime/ThrowingErrorSink.cs +++ b/src/core/IronPython/Runtime/ThrowingErrorSink.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using Microsoft.Scripting; using IronPython.Runtime.Operations; diff --git a/src/core/IronPython/Runtime/Types/CachedNewTypeInfo.cs b/src/core/IronPython/Runtime/Types/CachedNewTypeInfo.cs index b3f1d7337..288ddf33c 100644 --- a/src/core/IronPython/Runtime/Types/CachedNewTypeInfo.cs +++ b/src/core/IronPython/Runtime/Types/CachedNewTypeInfo.cs @@ -2,9 +2,11 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Collections.Generic; -using System.Text; + using Microsoft.Scripting.Utils; namespace IronPython.Runtime.Types { diff --git a/src/core/IronPython/Runtime/Types/ConstructorFunction.cs b/src/core/IronPython/Runtime/Types/ConstructorFunction.cs index 37e936e9a..84b175cac 100644 --- a/src/core/IronPython/Runtime/Types/ConstructorFunction.cs +++ b/src/core/IronPython/Runtime/Types/ConstructorFunction.cs @@ -2,12 +2,13 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System.Collections.Generic; using System.Reflection; -using Microsoft.Scripting.Utils; using System.Text; -using IronPython.Runtime.Operations; -using Microsoft.Scripting; + +using Microsoft.Scripting.Utils; namespace IronPython.Runtime.Types { [PythonType("builtin_function_or_method")] @@ -57,7 +58,5 @@ public override string __doc__ { return sb.ToString(); } } - - } } diff --git a/src/core/IronPython/Runtime/Types/CustomAttributeTracker.cs b/src/core/IronPython/Runtime/Types/CustomAttributeTracker.cs index e211d2514..2ffd2b2d7 100644 --- a/src/core/IronPython/Runtime/Types/CustomAttributeTracker.cs +++ b/src/core/IronPython/Runtime/Types/CustomAttributeTracker.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System.Linq.Expressions; using System; @@ -43,7 +45,7 @@ public override DynamicMetaObject SetValue(OverloadResolverFactory resolverFacto protected override DynamicMetaObject GetBoundValue(OverloadResolverFactory factory, ActionBinder binder, Type instanceType, DynamicMetaObject instance) { return new DynamicMetaObject( Ast.Call( - typeof(PythonOps).GetMethod(nameof(PythonOps.SlotGetValue)), + typeof(PythonOps).GetMethod(nameof(PythonOps.SlotGetValue))!, ((PythonOverloadResolverFactory)factory)._codeContext, AstUtils.Constant(GetSlot(), typeof(PythonTypeSlot)), AstUtils.Convert( @@ -60,11 +62,11 @@ protected override DynamicMetaObject SetBoundValue(OverloadResolverFactory resol return SetBoundValue(resolverFactory, binder, type, value, instance, null); } - protected override DynamicMetaObject SetBoundValue(OverloadResolverFactory factory, ActionBinder binder, Type type, DynamicMetaObject value, DynamicMetaObject instance, DynamicMetaObject errorSuggestion) { + protected override DynamicMetaObject SetBoundValue(OverloadResolverFactory factory, ActionBinder binder, Type type, DynamicMetaObject value, DynamicMetaObject instance, DynamicMetaObject? errorSuggestion) { return new DynamicMetaObject( Expression.Condition( Ast.Call( - typeof(PythonOps).GetMethod(nameof(PythonOps.SlotTrySetValue)), + typeof(PythonOps).GetMethod(nameof(PythonOps.SlotTrySetValue))!, ((PythonOverloadResolverFactory)factory)._codeContext, AstUtils.Constant(GetSlot(), typeof(PythonTypeSlot)), AstUtils.Convert( @@ -79,7 +81,7 @@ protected override DynamicMetaObject SetBoundValue(OverloadResolverFactory facto errorSuggestion.Expression : Expression.Throw( Expression.Call( - typeof(PythonOps).GetMethod(nameof(PythonOps.AttributeErrorForMissingAttribute), new Type[] { typeof(object), typeof(string) }), + typeof(PythonOps).GetMethod(nameof(PythonOps.AttributeErrorForMissingAttribute), new Type[] { typeof(object), typeof(string) })!, instance.Expression, Expression.Constant(Name) ), @@ -101,10 +103,6 @@ internal class CustomAttributeTracker : PythonCustomTracker { private readonly string/*!*/ _name; public CustomAttributeTracker(Type/*!*/ declaringType, string/*!*/ name, PythonTypeSlot/*!*/ slot) { - Debug.Assert(slot != null); - Debug.Assert(declaringType != null); - Debug.Assert(name != null); - _declType = declaringType; _name = name; _slot = slot; @@ -176,9 +174,6 @@ internal class OperatorTracker : PythonCustomTracker { private Type/*!*/ _declType; public OperatorTracker(Type/*!*/ declaringType, string/*!*/ name, bool reversed, params MethodTracker/*!*/[]/*!*/ members) { - Debug.Assert(declaringType != null); - Debug.Assert(members != null); - Debug.Assert(name != null); Debug.Assert(members.Length > 0); _declType = declaringType; diff --git a/src/core/IronPython/Runtime/Types/CustomInstanceDictionaryStorage.cs b/src/core/IronPython/Runtime/Types/CustomInstanceDictionaryStorage.cs index 1048c8d17..5682d9d1e 100644 --- a/src/core/IronPython/Runtime/Types/CustomInstanceDictionaryStorage.cs +++ b/src/core/IronPython/Runtime/Types/CustomInstanceDictionaryStorage.cs @@ -6,10 +6,10 @@ using System; using System.Collections.Generic; -using System.Diagnostics; +using System.Threading; + using Microsoft.Scripting; using Microsoft.Scripting.Runtime; -using System.Threading; namespace IronPython.Runtime.Types { /// diff --git a/src/core/IronPython/Runtime/Types/DynamicBaseTypeAttribute.cs b/src/core/IronPython/Runtime/Types/DynamicBaseTypeAttribute.cs index 07f78895e..be8b6a76a 100644 --- a/src/core/IronPython/Runtime/Types/DynamicBaseTypeAttribute.cs +++ b/src/core/IronPython/Runtime/Types/DynamicBaseTypeAttribute.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; namespace IronPython.Runtime.Types { diff --git a/src/core/IronPython/Runtime/Types/FunctionType.cs b/src/core/IronPython/Runtime/Types/FunctionType.cs index fbbf58982..fbd37d3c3 100644 --- a/src/core/IronPython/Runtime/Types/FunctionType.cs +++ b/src/core/IronPython/Runtime/Types/FunctionType.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; namespace IronPython.Runtime.Types { diff --git a/src/core/IronPython/Runtime/Types/IPythonObject.cs b/src/core/IronPython/Runtime/Types/IPythonObject.cs index ddb80f12f..09bd75e1a 100644 --- a/src/core/IronPython/Runtime/Types/IPythonObject.cs +++ b/src/core/IronPython/Runtime/Types/IPythonObject.cs @@ -2,8 +2,7 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System; -using Microsoft.Scripting; +#nullable enable namespace IronPython.Runtime.Types { /// @@ -11,9 +10,7 @@ namespace IronPython.Runtime.Types { /// is not intended for consumption from user programs. /// public interface IPythonObject { - PythonDictionary Dict { - get; - } + PythonDictionary? Dict { get; } /// /// Thread-safe dictionary set. Returns the dictionary set or the previous value if already set or @@ -21,7 +18,7 @@ PythonDictionary Dict { /// /// /// - PythonDictionary SetDict(PythonDictionary dict); + PythonDictionary? SetDict(PythonDictionary dict); /// /// Dictionary replacement. Returns true if replaced, false if the dictionary set isn't supported. /// @@ -29,13 +26,11 @@ PythonDictionary Dict { /// bool ReplaceDict(PythonDictionary dict); - PythonType PythonType { - get; - } + PythonType PythonType { get; } void SetPythonType(PythonType newType); - object[] GetSlots(); + object[]? GetSlots(); object[] GetSlotsCreate(); } } diff --git a/src/core/IronPython/Runtime/Types/InstanceCreator.cs b/src/core/IronPython/Runtime/Types/InstanceCreator.cs index db81d2a18..0db423b9a 100644 --- a/src/core/IronPython/Runtime/Types/InstanceCreator.cs +++ b/src/core/IronPython/Runtime/Types/InstanceCreator.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Runtime.CompilerServices; using System.Threading; @@ -42,11 +44,11 @@ public static InstanceCreator Make(PythonType type) { } internal class UserInstanceCreator : InstanceCreator { - private CallSite> _ctorSite; - private CallSite> _ctorSite0; - private CallSite> _ctorSite1; - private CallSite> _ctorSite2; - private CallSite> _ctorSite3; + private CallSite>? _ctorSite; + private CallSite>? _ctorSite0; + private CallSite>? _ctorSite1; + private CallSite>? _ctorSite2; + private CallSite>? _ctorSite3; public UserInstanceCreator(PythonType/*!*/ type) : base(type) { @@ -134,16 +136,16 @@ internal override object CreateInstance(CodeContext context, params object[] arg } internal override object CreateInstance(CodeContext context, object[] args, string[] names) { - return PythonCalls.CallWithKeywordArgs(context, Type.Ctor, ArrayUtils.Insert(Type, args), names); + return PythonCalls.CallWithKeywordArgs(context, Type.Ctor, ArrayUtils.Insert(Type, args), names)!; } } internal class SystemInstanceCreator : InstanceCreator { - private CallSite> _ctorSite; - private CallSite> _ctorSite0; - private CallSite> _ctorSite1; - private CallSite> _ctorSite2; - private CallSite> _ctorSite3; + private CallSite>? _ctorSite; + private CallSite>? _ctorSite0; + private CallSite>? _ctorSite1; + private CallSite>? _ctorSite2; + private CallSite>? _ctorSite3; public SystemInstanceCreator(PythonType/*!*/ type) : base(type) { @@ -230,7 +232,7 @@ internal override object CreateInstance(CodeContext context, params object[] arg } internal override object CreateInstance(CodeContext context, object[] args, string[] names) { - return PythonCalls.CallWithKeywordArgs(context, Type.Ctor, args, names); + return PythonCalls.CallWithKeywordArgs(context, Type.Ctor, args, names)!; } } } diff --git a/src/core/IronPython/Runtime/Types/OperatorMapping.cs b/src/core/IronPython/Runtime/Types/OperatorMapping.cs index a8448658e..d9aa7c46f 100644 --- a/src/core/IronPython/Runtime/Types/OperatorMapping.cs +++ b/src/core/IronPython/Runtime/Types/OperatorMapping.cs @@ -1,6 +1,12 @@ -using System; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +#nullable enable + +using System; using System.Collections.Generic; -using System.Text; + using IronPython.Runtime.Binding; namespace IronPython.Runtime.Types { @@ -13,7 +19,7 @@ internal class OperatorMapping { private readonly PythonOperationKind _operator; private readonly string _name; - private OperatorMapping(PythonOperationKind op, string name, string altName, Type alternateExpectedType = null) { + private OperatorMapping(PythonOperationKind op, string name, string? altName, Type? alternateExpectedType = null) { _operator = op; _name = name; AlternateName = altName; @@ -23,14 +29,14 @@ private OperatorMapping(PythonOperationKind op, string name, string altName, Typ /// /// Given an operator returns the OperatorMapping associated with the operator or null /// - public static OperatorMapping GetOperatorMapping(PythonOperationKind op) { + public static OperatorMapping? GetOperatorMapping(PythonOperationKind op) { foreach (OperatorMapping info in _infos) { if (info._operator == op) return info; } return null; } - public static OperatorMapping GetOperatorMapping(string name) { + public static OperatorMapping? GetOperatorMapping(string name) { foreach (OperatorMapping info in _infos) { if (info.Name == name || info.AlternateName == name) { return info; @@ -58,14 +64,14 @@ public string Name { /// Gets the secondary method name associated with the method. This method name is /// usually a standard .NET method name with pascal casing (e.g. Add). /// - public string AlternateName { get; } + public string? AlternateName { get; } /// /// Gets the return type that must match for the alternate operator to be valid. /// This is available alternate operators don't have special names and therefore /// could be confused for a normal method which isn't fulfilling the contract. /// - public Type AlternateExpectedType { get; } + public Type? AlternateExpectedType { get; } private static OperatorMapping[] MakeOperatorTable() { List res = new List(); @@ -109,7 +115,7 @@ private static OperatorMapping[] MakeOperatorTable() { res.Add(new OperatorMapping(PythonOperationKind.InPlaceBitwiseAnd, "op_BitwiseAndAssignment", "InPlaceBitwiseAnd")); // &= res.Add(new OperatorMapping(PythonOperationKind.InPlaceBitwiseOr, "op_BitwiseOrAssignment", "InPlaceBitwiseOr")); // |= res.Add(new OperatorMapping(PythonOperationKind.InPlaceTrueDivide, "op_DivisionAssignment", "InPlaceDivide")); // /= - + // these exist just for TypeInfo to map by name res.Add(new OperatorMapping(PythonOperationKind.GetItem, "get_Item", "GetItem")); // not defined res.Add(new OperatorMapping(PythonOperationKind.SetItem, "set_Item", "SetItem")); // not defined diff --git a/src/core/IronPython/Runtime/Types/PythonAssemblyOps.cs b/src/core/IronPython/Runtime/Types/PythonAssemblyOps.cs index c9afd3a8e..a97188371 100644 --- a/src/core/IronPython/Runtime/Types/PythonAssemblyOps.cs +++ b/src/core/IronPython/Runtime/Types/PythonAssemblyOps.cs @@ -2,11 +2,14 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System.Collections.Generic; -using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; + using IronPython.Runtime.Types; + using Microsoft.Scripting; using Microsoft.Scripting.Actions; using Microsoft.Scripting.Runtime; @@ -40,7 +43,6 @@ public static object GetBoundMember(CodeContext/*!*/ context, Assembly self, str [SpecialName] public static PythonList GetMemberNames(CodeContext/*!*/ context, Assembly self) { - Debug.Assert(self != null); PythonList ret = DynamicHelpers.GetPythonTypeFromType(self.GetType()).GetMemberNames(context); foreach (object o in GetReflectedAssembly(context, self).Keys) { @@ -59,10 +61,9 @@ public static object __repr__(Assembly self) { } private static TopNamespaceTracker GetReflectedAssembly(CodeContext/*!*/ context, Assembly assem) { - Debug.Assert(assem != null); var assemblyMap = GetAssemblyMap(context.LanguageContext as PythonContext); lock (assemblyMap) { - TopNamespaceTracker reflectedAssembly; + TopNamespaceTracker? reflectedAssembly; if (assemblyMap.TryGetValue(assem, out reflectedAssembly)) return reflectedAssembly; @@ -73,5 +74,5 @@ private static TopNamespaceTracker GetReflectedAssembly(CodeContext/*!*/ context return reflectedAssembly; } } - } + } } diff --git a/src/core/IronPython/Runtime/Types/PythonTypeDataSlot.cs b/src/core/IronPython/Runtime/Types/PythonTypeDataSlot.cs index a17d1ee9a..044e84043 100644 --- a/src/core/IronPython/Runtime/Types/PythonTypeDataSlot.cs +++ b/src/core/IronPython/Runtime/Types/PythonTypeDataSlot.cs @@ -2,9 +2,7 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System; -using System.Collections.Generic; -using System.Text; +#nullable enable using IronPython.Runtime.Operations; diff --git a/src/core/IronPython/Runtime/Types/PythonTypeTypeSlot.cs b/src/core/IronPython/Runtime/Types/PythonTypeTypeSlot.cs index 3c18fcfbe..6dd358f8b 100644 --- a/src/core/IronPython/Runtime/Types/PythonTypeTypeSlot.cs +++ b/src/core/IronPython/Runtime/Types/PythonTypeTypeSlot.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using IronPython.Runtime.Operations; namespace IronPython.Runtime.Types { @@ -40,7 +42,7 @@ internal override bool TrySetValue(CodeContext context, object instance, PythonT if (!(value is PythonType dt)) throw PythonOps.TypeError("__class__ must be set to a class, not '{0}' object", PythonOps.GetPythonTypeName(value)); - if(dt.UnderlyingSystemType != DynamicHelpers.GetPythonType(instance).UnderlyingSystemType) + if (dt.UnderlyingSystemType != DynamicHelpers.GetPythonType(instance).UnderlyingSystemType) throw PythonOps.TypeErrorForIncompatibleObjectLayout("__class__ assignment", DynamicHelpers.GetPythonType(instance), dt.UnderlyingSystemType); sdo.SetPythonType(dt); diff --git a/src/core/IronPython/Runtime/Types/ResolvedMember.cs b/src/core/IronPython/Runtime/Types/ResolvedMember.cs index 159baf3c3..62dfaa6ee 100644 --- a/src/core/IronPython/Runtime/Types/ResolvedMember.cs +++ b/src/core/IronPython/Runtime/Types/ResolvedMember.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System.Diagnostics; +#nullable enable using Microsoft.Scripting.Actions; @@ -16,9 +16,6 @@ internal class ResolvedMember { public static readonly ResolvedMember[]/*!*/ Empty = System.Array.Empty(); public ResolvedMember(string/*!*/ name, MemberGroup/*!*/ member) { - Debug.Assert(name != null); - Debug.Assert(member != null); - Name = name; Member = member; } diff --git a/src/core/IronPython/Runtime/Types/SlotFieldAttribute.cs b/src/core/IronPython/Runtime/Types/SlotFieldAttribute.cs index ee6bb3783..6477a5bd6 100644 --- a/src/core/IronPython/Runtime/Types/SlotFieldAttribute.cs +++ b/src/core/IronPython/Runtime/Types/SlotFieldAttribute.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; namespace IronPython.Runtime.Types { diff --git a/src/core/IronPython/Runtime/Types/TypeCache.Generated.cs b/src/core/IronPython/Runtime/Types/TypeCache.Generated.cs index a1c36d561..8de6b9ba0 100644 --- a/src/core/IronPython/Runtime/Types/TypeCache.Generated.cs +++ b/src/core/IronPython/Runtime/Types/TypeCache.Generated.cs @@ -2,14 +2,15 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System; +#nullable enable -using Microsoft.Scripting.Runtime; +using System; +using System.Numerics; using IronPython.Modules; using IronPython.Runtime.Exceptions; -using System.Numerics; +using Microsoft.Scripting.Runtime; namespace IronPython.Runtime.Types { public static class TypeCache { @@ -18,33 +19,33 @@ public static class TypeCache { // *** BEGIN GENERATED CODE *** // generated by function: gen_typecache_storage from: generate_typecache.py - private static PythonType array; - private static PythonType builtinfunction; - private static PythonType pythondictionary; - private static PythonType frozensetcollection; - private static PythonType pythonfunction; - private static PythonType builtin; - private static PythonType obj; - private static PythonType setcollection; - private static PythonType pythontype; - private static PythonType str; - private static PythonType bytes; - private static PythonType bytearray; - private static PythonType pythontuple; - private static PythonType weakreference; - private static PythonType pythonlist; - private static PythonType pythonmodule; - private static PythonType method; - private static PythonType enumerate; - private static PythonType intType; - private static PythonType singleType; - private static PythonType doubleType; - private static PythonType biginteger; - private static PythonType complex; - private static PythonType super; - private static PythonType nullType; - private static PythonType boolType; - private static PythonType baseException; + private static PythonType? array; + private static PythonType? builtinfunction; + private static PythonType? pythondictionary; + private static PythonType? frozensetcollection; + private static PythonType? pythonfunction; + private static PythonType? builtin; + private static PythonType? obj; + private static PythonType? setcollection; + private static PythonType? pythontype; + private static PythonType? str; + private static PythonType? bytes; + private static PythonType? bytearray; + private static PythonType? pythontuple; + private static PythonType? weakreference; + private static PythonType? pythonlist; + private static PythonType? pythonmodule; + private static PythonType? method; + private static PythonType? enumerate; + private static PythonType? intType; + private static PythonType? singleType; + private static PythonType? doubleType; + private static PythonType? biginteger; + private static PythonType? complex; + private static PythonType? super; + private static PythonType? nullType; + private static PythonType? boolType; + private static PythonType? baseException; // *** END GENERATED CODE *** @@ -55,195 +56,86 @@ public static class TypeCache { // *** BEGIN GENERATED CODE *** // generated by function: gen_typecache from: generate_typecache.py - public static PythonType Array { - get { - if (array == null) array = DynamicHelpers.GetPythonTypeFromType(typeof(Array)); - return array; - } - } - - public static PythonType BuiltinFunction { - get { - if (builtinfunction == null) builtinfunction = DynamicHelpers.GetPythonTypeFromType(typeof(BuiltinFunction)); - return builtinfunction; - } - } - - public static PythonType Dict { - get { - if (pythondictionary == null) pythondictionary = DynamicHelpers.GetPythonTypeFromType(typeof(PythonDictionary)); - return pythondictionary; - } - } - - public static PythonType FrozenSet { - get { - if (frozensetcollection == null) frozensetcollection = DynamicHelpers.GetPythonTypeFromType(typeof(FrozenSetCollection)); - return frozensetcollection; - } - } - - public static PythonType Function { - get { - if (pythonfunction == null) pythonfunction = DynamicHelpers.GetPythonTypeFromType(typeof(PythonFunction)); - return pythonfunction; - } - } - - public static PythonType Builtin { - get { - if (builtin == null) builtin = DynamicHelpers.GetPythonTypeFromType(typeof(Builtin)); - return builtin; - } - } - - public static PythonType Object { - get { - if (obj == null) obj = DynamicHelpers.GetPythonTypeFromType(typeof(Object)); - return obj; - } - } - - public static PythonType Set { - get { - if (setcollection == null) setcollection = DynamicHelpers.GetPythonTypeFromType(typeof(SetCollection)); - return setcollection; - } - } - - public static PythonType PythonType { - get { - if (pythontype == null) pythontype = DynamicHelpers.GetPythonTypeFromType(typeof(PythonType)); - return pythontype; - } - } - - public static PythonType String { - get { - if (str == null) str = DynamicHelpers.GetPythonTypeFromType(typeof(String)); - return str; - } - } - - public static PythonType Bytes { - get { - if (bytes == null) bytes = DynamicHelpers.GetPythonTypeFromType(typeof(Bytes)); - return bytes; - } - } - - public static PythonType ByteArray { - get { - if (bytearray == null) bytearray = DynamicHelpers.GetPythonTypeFromType(typeof(ByteArray)); - return bytearray; - } - } - - public static PythonType PythonTuple { - get { - if (pythontuple == null) pythontuple = DynamicHelpers.GetPythonTypeFromType(typeof(PythonTuple)); - return pythontuple; - } - } - - public static PythonType WeakReference { - get { - if (weakreference == null) weakreference = DynamicHelpers.GetPythonTypeFromType(typeof(WeakReference)); - return weakreference; - } - } - - public static PythonType PythonList { - get { - if (pythonlist == null) pythonlist = DynamicHelpers.GetPythonTypeFromType(typeof(PythonList)); - return pythonlist; - } - } - - public static PythonType Module { - get { - if (pythonmodule == null) pythonmodule = DynamicHelpers.GetPythonTypeFromType(typeof(PythonModule)); - return pythonmodule; - } - } - - public static PythonType Method { - get { - if (method == null) method = DynamicHelpers.GetPythonTypeFromType(typeof(Method)); - return method; - } - } - - public static PythonType Enumerate { - get { - if (enumerate == null) enumerate = DynamicHelpers.GetPythonTypeFromType(typeof(Enumerate)); - return enumerate; - } - } - - public static PythonType Int32 { - get { - if (intType == null) intType = DynamicHelpers.GetPythonTypeFromType(typeof(Int32)); - return intType; - } - } - - public static PythonType Single { - get { - if (singleType == null) singleType = DynamicHelpers.GetPythonTypeFromType(typeof(Single)); - return singleType; - } - } - - public static PythonType Double { - get { - if (doubleType == null) doubleType = DynamicHelpers.GetPythonTypeFromType(typeof(Double)); - return doubleType; - } - } - - public static PythonType BigInteger { - get { - if (biginteger == null) biginteger = DynamicHelpers.GetPythonTypeFromType(typeof(BigInteger)); - return biginteger; - } - } - - public static PythonType Complex { - get { - if (complex == null) complex = DynamicHelpers.GetPythonTypeFromType(typeof(Complex)); - return complex; - } - } - - public static PythonType Super { - get { - if (super == null) super = DynamicHelpers.GetPythonTypeFromType(typeof(Super)); - return super; - } - } - - public static PythonType Null { - get { - if (nullType == null) nullType = DynamicHelpers.GetPythonTypeFromType(typeof(DynamicNull)); - return nullType; - } - } - - public static PythonType Boolean { - get { - if (boolType == null) boolType = DynamicHelpers.GetPythonTypeFromType(typeof(Boolean)); - return boolType; - } - } - - public static PythonType BaseException { - get { - if (baseException == null) baseException = DynamicHelpers.GetPythonTypeFromType(typeof(PythonExceptions.BaseException)); - return baseException; - } - } + public static PythonType Array + => array ??= DynamicHelpers.GetPythonTypeFromType(typeof(Array)); + + public static PythonType BuiltinFunction + => builtinfunction ??= DynamicHelpers.GetPythonTypeFromType(typeof(BuiltinFunction)); + + public static PythonType Dict + => pythondictionary ??= DynamicHelpers.GetPythonTypeFromType(typeof(PythonDictionary)); + + public static PythonType FrozenSet + => frozensetcollection ??= DynamicHelpers.GetPythonTypeFromType(typeof(FrozenSetCollection)); + + public static PythonType Function + => pythonfunction ??= DynamicHelpers.GetPythonTypeFromType(typeof(PythonFunction)); + + public static PythonType Builtin + => builtin ??= DynamicHelpers.GetPythonTypeFromType(typeof(Builtin)); + + public static PythonType Object + => obj ??= DynamicHelpers.GetPythonTypeFromType(typeof(Object)); + + public static PythonType Set + => setcollection ??= DynamicHelpers.GetPythonTypeFromType(typeof(SetCollection)); + + public static PythonType PythonType + => pythontype ??= DynamicHelpers.GetPythonTypeFromType(typeof(PythonType)); + + public static PythonType String + => str ??= DynamicHelpers.GetPythonTypeFromType(typeof(String)); + + public static PythonType Bytes + => bytes ??= DynamicHelpers.GetPythonTypeFromType(typeof(Bytes)); + + public static PythonType ByteArray + => bytearray ??= DynamicHelpers.GetPythonTypeFromType(typeof(ByteArray)); + + public static PythonType PythonTuple + => pythontuple ??= DynamicHelpers.GetPythonTypeFromType(typeof(PythonTuple)); + + public static PythonType WeakReference + => weakreference ??= DynamicHelpers.GetPythonTypeFromType(typeof(WeakReference)); + + public static PythonType PythonList + => pythonlist ??= DynamicHelpers.GetPythonTypeFromType(typeof(PythonList)); + + public static PythonType Module + => pythonmodule ??= DynamicHelpers.GetPythonTypeFromType(typeof(PythonModule)); + + public static PythonType Method + => method ??= DynamicHelpers.GetPythonTypeFromType(typeof(Method)); + + public static PythonType Enumerate + => enumerate ??= DynamicHelpers.GetPythonTypeFromType(typeof(Enumerate)); + + public static PythonType Int32 + => intType ??= DynamicHelpers.GetPythonTypeFromType(typeof(Int32)); + + public static PythonType Single + => singleType ??= DynamicHelpers.GetPythonTypeFromType(typeof(Single)); + + public static PythonType Double + => doubleType ??= DynamicHelpers.GetPythonTypeFromType(typeof(Double)); + + public static PythonType BigInteger + => biginteger ??= DynamicHelpers.GetPythonTypeFromType(typeof(BigInteger)); + + public static PythonType Complex + => complex ??= DynamicHelpers.GetPythonTypeFromType(typeof(Complex)); + + public static PythonType Super + => super ??= DynamicHelpers.GetPythonTypeFromType(typeof(Super)); + + public static PythonType Null + => nullType ??= DynamicHelpers.GetPythonTypeFromType(typeof(DynamicNull)); + + public static PythonType Boolean + => boolType ??= DynamicHelpers.GetPythonTypeFromType(typeof(Boolean)); + public static PythonType BaseException + => baseException ??= DynamicHelpers.GetPythonTypeFromType(typeof(PythonExceptions.BaseException)); // *** END GENERATED CODE *** diff --git a/src/core/IronPython/Runtime/UnboundNameException.cs b/src/core/IronPython/Runtime/UnboundNameException.cs index a7cb6590f..a4e8162f5 100644 --- a/src/core/IronPython/Runtime/UnboundNameException.cs +++ b/src/core/IronPython/Runtime/UnboundNameException.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Runtime.Serialization; diff --git a/src/core/IronPython/Runtime/WrapperDescriptorAttribute.cs b/src/core/IronPython/Runtime/WrapperDescriptorAttribute.cs index abc422cb6..2a32e92f7 100644 --- a/src/core/IronPython/Runtime/WrapperDescriptorAttribute.cs +++ b/src/core/IronPython/Runtime/WrapperDescriptorAttribute.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. +#nullable enable + using System; namespace IronPython.Runtime {