| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent aa87074 commit 6daccdd
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -205,7 +205,7 @@ def InitializeComponent(self): | |||
| 205 | 205 | self.richTextBox.TabIndex = 0 | |
| 206 | 206 | self.richTextBox.AutoSize = 1 | |
| 207 | 207 | self.richTextBox.ScrollBars = WinForms.RichTextBoxScrollBars.ForcedBoth | |
| 208 | - self.richTextBox.Font = System.Drawing.Font("Tahoma", 10) | ||
| 208 | + self.richTextBox.Font = System.Drawing.Font("Tahoma", 10.0) | ||
| 209 | 209 | self.richTextBox.AcceptsTab = 1 | |
| 210 | 210 | self.richTextBox.Location = System.Drawing.Point(0, 0) | |
| 211 | 211 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,7 +29,10 @@ private Converter() {} | |||
| 29 | 29 | static NumberFormatInfo nfi; | |
| 30 | 30 | static Type objectType; | |
| 31 | 31 | static Type stringType; | |
| 32 | + static Type singleType; | ||
| 32 | 33 | static Type doubleType; | |
| 34 | + static Type decimalType; | ||
| 35 | + static Type int16Type; | ||
| 33 | 36 | static Type int32Type; | |
| 34 | 37 | static Type int64Type; | |
| 35 | 38 | static Type flagsType; | |
@@ -40,9 +43,12 @@ static Converter () { | |||
| 40 | 43 | nfi = NumberFormatInfo.InvariantInfo; | |
| 41 | 44 | objectType = typeof(Object); | |
| 42 | 45 | stringType = typeof(String); | |
| 46 | + int16Type = typeof(Int16); | ||
| 43 | 47 | int32Type = typeof(Int32); | |
| 44 | 48 | int64Type = typeof(Int64); | |
| 49 | + singleType = typeof(Single); | ||
| 45 | 50 | doubleType = typeof(Double); | |
| 51 | + decimalType = typeof(Decimal); | ||
| 46 | 52 | flagsType = typeof(FlagsAttribute); | |
| 47 | 53 | boolType = typeof(Boolean); | |
| 48 | 54 | typeType = typeof(Type); | |
@@ -73,6 +79,35 @@ internal static Type GetTypeByAlias(IntPtr op) { | |||
| 73 | 79 | return null; | |
| 74 | 80 | } | |
| 75 | 81 | ||
| 82 | + internal static IntPtr GetPythonTypeByAlias(Type op) | ||
| 83 | + { | ||
| 84 | + if (op == stringType) { | ||
| 85 | + return Runtime.PyUnicodeType; | ||
| 86 | + } | ||
| 87 | + #if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35) | ||
| 88 | + else if ((op == int16Type) || | ||
| 89 | + (op == int32Type) || | ||
| 90 | + (op == int64Type)) { | ||
| 91 | + return Runtime.PyIntType; | ||
| 92 | + } | ||
| 93 | + #endif | ||
| 94 | + else if ((op == int16Type) || | ||
| 95 | + (op == int32Type)) { | ||
| 96 | + return Runtime.PyIntType; | ||
| 97 | + } | ||
| 98 | + else if (op == int64Type) { | ||
| 99 | + return Runtime.PyLongType; | ||
| 100 | + } | ||
| 101 | + else if ((op == doubleType) || | ||
| 102 | + (op == singleType)) { | ||
| 103 | + return Runtime.PyFloatType; | ||
| 104 | + } | ||
| 105 | + else if (op == boolType) { | ||
| 106 | + return Runtime.PyBoolType; | ||
| 107 | + } | ||
| 108 | + return IntPtr.Zero; | ||
| 109 | + } | ||
| 110 | + | ||
| 76 | 111 | ||
| 77 | 112 | //==================================================================== | |
| 78 | 113 | // Return a Python object for the given native object, converting | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -245,7 +245,7 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, | |||
| 245 | 245 | else { | |
| 246 | 246 | _methods = GetMethods(); | |
| 247 | 247 | } | |
| 248 | - Type type; | ||
| 248 | + Type clrtype; | ||
| 249 | 249 | for (int i = 0; i < _methods.Length; i++) { | |
| 250 | 250 | MethodBase mi = _methods[i]; | |
| 251 | 251 | ||
@@ -295,34 +295,52 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, | |||
| 295 | 295 | // this logic below handles cases when multiple overloading methods | |
| 296 | 296 | // are ambiguous, hence comparison between Python and CLR types | |
| 297 | 297 | // is necessary | |
| 298 | - type = null; | ||
| 299 | - | ||
| 300 | - if (_methods.Length>1) { | ||
| 301 | - IntPtr pyoptype = IntPtr.Zero; | ||
| 298 | + clrtype = null; | ||
| 299 | + IntPtr pyoptype; | ||
| 300 | + if (_methods.Length > 1) { | ||
| 301 | + pyoptype = IntPtr.Zero; | ||
| 302 | 302 | pyoptype = Runtime.PyObject_Type(op); | |
| 303 | 303 | Exceptions.Clear(); | |
| 304 | - if (pyoptype != IntPtr.Zero) { } | ||
| 305 | - type = Converter.GetTypeByAlias(pyoptype); | ||
| 306 | - Runtime.Decref(pyoptype); | ||
| 304 | + if (pyoptype != IntPtr.Zero) { | ||
| 305 | + clrtype = Converter.GetTypeByAlias(pyoptype); | ||
| 307 | 306 | } | |
| 307 | + Runtime.Decref(pyoptype); | ||
| 308 | + } | ||
| 308 | 309 | ||
| 309 | 310 | ||
| 310 | - if (type != null) { | ||
| 311 | - if (pi[n].ParameterType != type) { | ||
| 312 | - margs = null; | ||
| 313 | - break; | ||
| 311 | + if (clrtype != null) { | ||
| 312 | + if (pi[n].ParameterType != clrtype) { | ||
| 313 | + IntPtr pytype = Converter.GetPythonTypeByAlias(pi[n].ParameterType); | ||
| 314 | + pyoptype = Runtime.PyObject_Type(op); | ||
| 315 | + Exceptions.Clear(); | ||
| 316 | + if (pyoptype != IntPtr.Zero) { | ||
| 317 | + if (pytype != pyoptype) { | ||
| 318 | + Runtime.Decref(pyoptype); | ||
| 319 | + margs = null; | ||
| 320 | + break; | ||
| 321 | + } | ||
| 322 | + else { | ||
| 323 | + clrtype = pi[n].ParameterType; | ||
| 324 | + } | ||
| 325 | + } | ||
| 326 | + else { | ||
| 327 | + Runtime.Decref(pyoptype); | ||
| 328 | + margs = null; | ||
| 329 | + break; | ||
| 330 | + } | ||
| 331 | + Runtime.Decref(pyoptype); | ||
| 314 | 332 | } | |
| 315 | 333 | } | |
| 316 | 334 | else { | |
| 317 | - type = pi[n].ParameterType; | ||
| 335 | + clrtype = pi[n].ParameterType; | ||
| 318 | 336 | } | |
| 319 | 337 | ||
| 320 | - if (pi[n].IsOut || type.IsByRef) | ||
| 338 | + if (pi[n].IsOut || clrtype.IsByRef) | ||
| 321 | 339 | { | |
| 322 | 340 | outs++; | |
| 323 | 341 | } | |
| 324 | 342 | ||
| 325 | - if (!Converter.ToManaged(op, type, out arg, false)) | ||
| 343 | + if (!Converter.ToManaged(op, clrtype, out arg, false)) | ||
| 326 | 344 | { | |
| 327 | 345 | Exceptions.Clear(); | |
| 328 | 346 | margs = null; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -341,6 +341,39 @@ def testGenericMethodTypeHandling(self): | |||
| 341 | 341 | self._testGenericMethodByType(InterfaceTest, InterfaceTest(), 1) | |
| 342 | 342 | self._testGenericMethodByType(ISayHello1, InterfaceTest(), 1) | |
| 343 | 343 | ||
| 344 | + def testCorrectOverloadSelection(self): | ||
| 345 | + """ | ||
| 346 | + Test correct overloading selection for common types. | ||
| 347 | + """ | ||
| 348 | + from System.Drawing import Font | ||
| 349 | + | ||
| 350 | + from System import (String, Double, Single, | ||
| 351 | + Int16, Int32, Int64) | ||
| 352 | + from System import Math | ||
| 353 | + | ||
| 354 | + substr = String("substring") | ||
| 355 | + self.assertTrue(substr.Substring(2) == substr.Substring.__overloads__[Int32]( | ||
| 356 | + Int32(2))) | ||
| 357 | + self.assertTrue(substr.Substring(2, 3) == substr.Substring.__overloads__[Int32,Int32]( | ||
| 358 | + Int32(2), Int32(3))) | ||
| 359 | + | ||
| 360 | + for atype, value1, value2 in zip([Double, Single, Int16, Int32, Int64], | ||
| 361 | + [1.0, 1.0, 1, 1, 1], | ||
| 362 | + [2.0, 0.5, 2, 0, -1]): | ||
| 363 | + self.assertTrue(Math.Abs(atype(value1)) == Math.Abs.__overloads__[atype](atype(value1))) | ||
| 364 | + self.assertTrue(Math.Abs(value1) == Math.Abs.__overloads__[atype](atype(value1))) | ||
| 365 | + self.assertTrue( | ||
| 366 | + Math.Max(atype(value1), | ||
| 367 | + atype(value2)) == Math.Max.__overloads__[atype, atype]( | ||
| 368 | + atype(value1), | ||
| 369 | + atype(value2))) | ||
| 370 | + if (atype is Int64) and six.PY2: | ||
| 371 | + value2 = long(value2) | ||
| 372 | + self.assertTrue( | ||
| 373 | + Math.Max(atype(value1), | ||
| 374 | + value2) == Math.Max.__overloads__[atype, atype]( | ||
| 375 | + atype(value1), | ||
| 376 | + atype(value2))) | ||
| 344 | 377 | ||
| 345 | 378 | def testGenericMethodOverloadSelection(self): | |
| 346 | 379 | """ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments