Skip to content

Commit 5fffcee

Browse files
authored
Merge pull request #10 from AlexCatarino/lean
Method overload with decimal parameter accepts non-decimal numbers
2 parents 079268a + 4e33d08 commit 5fffcee

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
## Contributors
1414

15+
- Alexandre Catarino([@AlexCatarino](https://github.com/AlexCatarino))
1516
- Arvid JB ([@ArvidJB](https://github.com/ArvidJB))
1617
- Bradley Friedman ([@leith-bartrich](https://github.com/leith-bartrich))
1718
- Callum Noble ([@callumnoble](https://github.com/callumnoble))

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
3131
- Fixed `clr.GetClrType` when iterating over `System` members (#607)
3232
- Fixed `LockRecursionException` when loading assemblies (#627)
3333
- Fixed errors breaking .NET Remoting on method invoke (#276)
34+
- Fixed missing information on 'No method matches given arguments' by adding the method name
3435

3536

3637
## [2.3.0][] - 2017-03-11

src/runtime/converter.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ internal static Type GetTypeByAlias(IntPtr op)
106106
if (op == Runtime.PyBoolType)
107107
return boolType;
108108

109+
if (op == Runtime.PyDecimalType)
110+
return decimalType;
111+
109112
return null;
110113
}
111114

@@ -136,7 +139,7 @@ internal static IntPtr GetPythonTypeByAlias(Type op)
136139
return Runtime.PyBoolType;
137140

138141
if (op == decimalType)
139-
return Runtime.PyFloatType;
142+
return Runtime.PyDecimalType;
140143

141144
return IntPtr.Zero;
142145
}

src/runtime/methodbinder.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,16 @@ internal static int GetPrecedence(MethodBase mi)
186186
val += ArgPrecedence(pi[i].ParameterType);
187187
}
188188

189+
var info = mi as MethodInfo;
190+
if (info != null)
191+
{
192+
val += ArgPrecedence(info.ReturnType);
193+
val += mi.DeclaringType == mi.ReflectedType ? 0 : 3000;
194+
}
195+
189196
return val;
190197
}
191-
198+
192199
/// <summary>
193200
/// Return a precedence value for a particular Type object.
194201
/// </summary>
@@ -200,6 +207,11 @@ internal static int ArgPrecedence(Type t)
200207
return 3000;
201208
}
202209

210+
if (t.IsAssignableFrom(typeof(PyObject)))
211+
{
212+
return -1;
213+
}
214+
203215
TypeCode tc = Type.GetTypeCode(t);
204216
// TODO: Clean up
205217
switch (tc)
@@ -408,6 +420,12 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
408420
typematch = true;
409421
clrtype = pi[n].ParameterType;
410422
}
423+
// accepts non-decimal numbers in decimal parameters
424+
if (underlyingType == typeof(decimal))
425+
{
426+
clrtype = pi[n].ParameterType;
427+
typematch = Converter.ToManaged(op, clrtype, out arg, false);
428+
}
411429
// this takes care of implicit conversions
412430
var opImplicit = pi[n].ParameterType.GetMethod("op_Implicit", new[] { clrtype });
413431
if (opImplicit != null)

src/runtime/runtime.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,14 @@ internal static void Initialize()
299299
PyFloatType = PyObject_Type(op);
300300
XDecref(op);
301301

302+
IntPtr decimalMod = PyImport_ImportModule("decimal");
303+
IntPtr decimalCtor = PyObject_GetAttrString(decimalMod, "Decimal");
304+
op = PyObject_CallObject(decimalCtor, IntPtr.Zero);
305+
PyDecimalType = PyObject_Type(op);
306+
XDecref(op);
307+
XDecref(decimalMod);
308+
XDecref(decimalCtor);
309+
302310
#if PYTHON3
303311
PyClassType = IntPtr.Zero;
304312
PyInstanceType = IntPtr.Zero;
@@ -392,6 +400,7 @@ internal static int AtExit()
392400
internal static IntPtr PyBoolType;
393401
internal static IntPtr PyNoneType;
394402
internal static IntPtr PyTypeType;
403+
internal static IntPtr PyDecimalType;
395404

396405
#if PYTHON3
397406
internal static IntPtr PyBytesType;

0 commit comments

Comments
 (0)