| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -710,7 +710,7 @@ internal static bool ToPrimitive(BorrowedReference value, Type obType, out objec | |||
| 710 | 710 | { | |
| 711 | 711 | if (Runtime.Is32Bit) | |
| 712 | 712 | { | |
| 713 | - if (!Runtime.PyLong_Check(value)) | ||
| 713 | + if (!Runtime.PyInt_Check(value)) | ||
| 714 | 714 | { | |
| 715 | 715 | goto type_error; | |
| 716 | 716 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1101,11 +1101,6 @@ internal static bool PyBool_Check(BorrowedReference ob) | |||
| 1101 | 1101 | ||
| 1102 | 1102 | internal static NewReference PyInt_FromInt64(long value) => PyLong_FromLongLong(value); | |
| 1103 | 1103 | ||
| 1104 | - internal static bool PyLong_Check(BorrowedReference ob) | ||
| 1105 | - { | ||
| 1106 | - return PyObject_TYPE(ob) == PyLongType; | ||
| 1107 | - } | ||
| 1108 | - | ||
| 1109 | 1104 | internal static NewReference PyLong_FromLongLong(long value) => Delegates.PyLong_FromLongLong(value); | |
| 1110 | 1105 | ||
| 1111 | 1106 | ||
@@ -1145,9 +1140,7 @@ internal static NewReference PyLong_FromString(string value, int radix) | |||
| 1145 | 1140 | } | |
| 1146 | 1141 | ||
| 1147 | 1142 | internal static bool PyFloat_Check(BorrowedReference ob) | |
| 1148 | - { | ||
| 1149 | - return PyObject_TYPE(ob) == PyFloatType; | ||
| 1150 | - } | ||
| 1143 | + => PyObject_TypeCheck(ob, PyFloatType); | ||
| 1151 | 1144 | ||
| 1152 | 1145 | /// <summary> | |
| 1153 | 1146 | /// Return value: New reference. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1256,3 +1256,41 @@ 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 IntAnswerMixin: | ||
| 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 Answer(int, IntAnswerMixin): | ||
| 1272 | + pass | ||
| 1273 | + | ||
| 1274 | + class FloatAnswer(float, IntAnswerMixin): | ||
| 1275 | + def __float__(self): | ||
| 1276 | + return 42.0 | ||
| 1277 | + | ||
| 1278 | + # TODO: This should also work for integer types but due to some complexities | ||
| 1279 | + # in the C-API functions (some call __int__/__index__, some don't), it's not | ||
| 1280 | + # supported, yet. | ||
| 1281 | + for v in [Answer(), FloatAnswer()]: | ||
| 1282 | + for t in [System.Double, System.Single]: | ||
| 1283 | + min_value = t(t.MinValue) | ||
| 1284 | + compare_to = min_value.CompareTo.__overloads__[t] | ||
| 1285 | + | ||
| 1286 | + assert compare_to(v) == -1 | ||
| 1287 | + | ||
| 1288 | + class SomeNonFloat: | ||
| 1289 | + def __float__(self): | ||
| 1290 | + return 42.0 | ||
| 1291 | + | ||
| 1292 | + for t in [System.Double, System.Single]: | ||
| 1293 | + with pytest.raises(TypeError): | ||
| 1294 | + min_value = t(t.MinValue) | ||
| 1295 | + compare_to = min_value.CompareTo.__overloads__[t] | ||
| 1296 | + assert compare_to(SomeNonFloat()) == -1 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments