Skip to content

Commit 310d50d

Browse files
committed
Use string interpolation
Removed extra newline at beginning from deprecation warning message
1 parent 58bc902 commit 310d50d

File tree

6 files changed

+15
-24
lines changed

6 files changed

+15
-24
lines changed

src/runtime/assemblymanager.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using System;
22
using System.Collections;
3-
using System.IO;
43
using System.Collections.Concurrent;
54
using System.Collections.Generic;
65
using System.Diagnostics;
6+
using System.IO;
77
using System.Reflection;
88
using System.Threading;
99

@@ -323,9 +323,8 @@ public static bool LoadImplicit(string name, bool warn = true)
323323
if (warn && loaded)
324324
{
325325
string location = Path.GetFileNameWithoutExtension(lastAssembly.Location);
326-
string deprWarning = $@"
327-
The module was found, but not in a referenced namespace.
328-
Implicit loading is deprecated. Please use clr.AddReference(""{location}"").";
326+
string deprWarning = "The module was found, but not in a referenced namespace.\n" +
327+
$"Implicit loading is deprecated. Please use clr.AddReference('{location}').";
329328
Exceptions.deprecation(deprWarning);
330329
}
331330

src/runtime/classbase.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ public static IntPtr tp_iter(IntPtr ob)
199199

200200
if (o == null)
201201
{
202-
var message = "iteration over non-sequence";
203-
return Exceptions.RaiseTypeError(message);
202+
return Exceptions.RaiseTypeError("iteration over non-sequence");
204203
}
205204
}
206205

src/runtime/classderived.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ public static void InvokeMethodVoid(IPythonDerivedType obj, string methodName, s
737737

738738
if (origMethodName == null)
739739
{
740-
throw new NotImplementedException("Python object does not have a '" + methodName + "' method");
740+
throw new NotImplementedException($"Python object does not have a '{methodName}' method");
741741
}
742742

743743
obj.GetType().InvokeMember(origMethodName,

src/runtime/constructorbinding.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ public static IntPtr mp_subscript(IntPtr op, IntPtr key)
104104
ConstructorInfo ci = self.type.GetConstructor(types);
105105
if (ci == null)
106106
{
107-
var msg = "No match found for constructor signature";
108-
return Exceptions.RaiseTypeError(msg);
107+
return Exceptions.RaiseTypeError("No match found for constructor signature");
109108
}
110109
var boundCtor = new BoundContructor(self.type, self.pyTypeHndl, self.ctorBinder, ci);
111110

src/runtime/converter.cs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using System;
2+
using System.Collections;
3+
using System.Globalization;
24
using System.Reflection;
35
using System.Runtime.InteropServices;
4-
using System.Globalization;
56
using System.Security;
6-
using System.Collections;
77

88
namespace Python.Runtime
99
{
@@ -292,9 +292,7 @@ internal static bool ToManagedValue(IntPtr value, Type obType,
292292
result = tmp;
293293
return true;
294294
}
295-
var err = "value cannot be converted to {0}";
296-
err = string.Format(err, obType);
297-
Exceptions.SetError(Exceptions.TypeError, err);
295+
Exceptions.SetError(Exceptions.TypeError, $"value cannot be converted to {obType}");
298296
return false;
299297
}
300298
if (mt is ClassBase)
@@ -793,10 +791,8 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
793791

794792
if (setError)
795793
{
796-
var format = "'{0}' value cannot be converted to {1}";
797794
string tpName = Runtime.PyObject_GetTypeName(value);
798-
string error = string.Format(format, tpName, obType);
799-
Exceptions.SetError(Exceptions.TypeError, error);
795+
Exceptions.SetError(Exceptions.TypeError, $"'{tpName}' value cannot be converted to {obType}");
800796
}
801797

802798
return false;
@@ -805,8 +801,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
805801

806802
if (setError)
807803
{
808-
var error = "value too large to convert";
809-
Exceptions.SetError(Exceptions.OverflowError, error);
804+
Exceptions.SetError(Exceptions.OverflowError, "value too large to convert");
810805
}
811806

812807
return false;
@@ -818,8 +813,7 @@ private static void SetConversionError(IntPtr value, Type target)
818813
IntPtr ob = Runtime.PyObject_Repr(value);
819814
string src = Runtime.GetManagedString(ob);
820815
Runtime.XDecref(ob);
821-
string error = string.Format("Cannot convert {0} to {1}", src, target);
822-
Exceptions.SetError(Exceptions.TypeError, error);
816+
Exceptions.SetError(Exceptions.TypeError, $"Cannot convert {src} to {target}");
823817
}
824818

825819

@@ -901,8 +895,7 @@ private static bool ToEnum(IntPtr value, Type obType, out object result, bool se
901895

902896
if (setError)
903897
{
904-
var error = "invalid enumeration value";
905-
Exceptions.SetError(Exceptions.ValueError, error);
898+
Exceptions.SetError(Exceptions.ValueError, "invalid enumeration value");
906899
}
907900

908901
return false;

src/runtime/moduleobject.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Reflection;
45
using System.Runtime.InteropServices;
56

@@ -396,7 +397,7 @@ public static Assembly AddReference(string name)
396397
}
397398
if (assembly == null)
398399
{
399-
throw new System.IO.FileNotFoundException($"Unable to find assembly '{name}'.");
400+
throw new FileNotFoundException($"Unable to find assembly '{name}'.");
400401
}
401402

402403
return assembly;

0 commit comments

Comments
 (0)