| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c7068a5 commit 0230e58
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -777,12 +777,8 @@ internal static bool ToPrimitive(BorrowedReference value, Type obType, out objec | |||
| 777 | 777 | ||
| 778 | 778 | case TypeCode.Single: | |
| 779 | 779 | { | |
| 780 | - if (!Runtime.PyFloat_Check(value) && !Runtime.PyInt_Check(value)) | ||
| 781 | - { | ||
| 782 | - goto type_error; | ||
| 783 | - } | ||
| 784 | 780 | double num = Runtime.PyFloat_AsDouble(value); | |
| 785 | - if (num == -1.0 && Exceptions.ErrorOccurred()) | ||
| 781 | + if (Exceptions.ErrorOccurred()) | ||
| 786 | 782 | { | |
| 787 | 783 | goto convert_error; | |
| 788 | 784 | } | |
@@ -799,12 +795,8 @@ internal static bool ToPrimitive(BorrowedReference value, Type obType, out objec | |||
| 799 | 795 | ||
| 800 | 796 | case TypeCode.Double: | |
| 801 | 797 | { | |
| 802 | - if (!Runtime.PyFloat_Check(value) && !Runtime.PyInt_Check(value)) | ||
| 803 | - { | ||
| 804 | - goto type_error; | ||
| 805 | - } | ||
| 806 | 798 | double num = Runtime.PyFloat_AsDouble(value); | |
| 807 | - if (num == -1.0 && Exceptions.ErrorOccurred()) | ||
| 799 | + if (Exceptions.ErrorOccurred()) | ||
| 808 | 800 | { | |
| 809 | 801 | goto convert_error; | |
| 810 | 802 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1256,3 +1256,28 @@ def test_method_encoding(): | |||
| 1256 | 1256 | def test_method_with_pointer_array_argument(): | |
| 1257 | 1257 | with pytest.raises(TypeError): | |
| 1258 | 1258 | MethodTest.PointerArray([0]) | |
| 1259 | + | ||
| 1260 | + def test_method_call_implicit_conversion(): | ||
| 1261 | + | ||
| 1262 | + class Answer: | ||
| 1263 | + # For Python >= 3.8 | ||
| 1264 | + def __index__(self): | ||
| 1265 | + return 42 | ||
| 1266 | + | ||
| 1267 | + # For Python < 3.10 | ||
| 1268 | + def __int__(self): | ||
| 1269 | + return 42 | ||
| 1270 | + | ||
| 1271 | + class FloatAnswer(Answer): | ||
| 1272 | + def __float__(self): | ||
| 1273 | + return 42.0 | ||
| 1274 | + | ||
| 1275 | + # TODO: This should also work for integer types but due to some complexities | ||
| 1276 | + # in the C-API functions (some call __int__/__index__, some don't), it's not | ||
| 1277 | + # supported, yet. | ||
| 1278 | + for v in [Answer(), FloatAnswer()]: | ||
| 1279 | + for t in [System.Double, System.Single]: | ||
| 1280 | + min_value = t(t.MinValue) | ||
| 1281 | + compare_to = min_value.CompareTo.__overloads__[t] | ||
| 1282 | + | ||
| 1283 | + assert compare_to(v) == -1 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments