Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d6c024c

Browse files
committed
explicit functions for exact type checks
1 parent ce76dae commit d6c024c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/runtime/Runtime.cs

+12-3
Original file line numberDiff line numberDiff line change
@@ -1094,8 +1094,13 @@ internal static nint PyBuffer_SizeFromFormat(string format)
10941094
internal static bool PyInt_Check(BorrowedReference ob)
10951095
=> PyObject_TypeCheck(ob, PyLongType);
10961096

1097+
internal static bool PyInt_CheckExact(BorrowedReference ob)
1098+
=> PyObject_TypeCheckExact(ob, PyLongType);
1099+
10971100
internal static bool PyBool_Check(BorrowedReference ob)
10981101
=> PyObject_TypeCheck(ob, PyBoolType);
1102+
internal static bool PyBool_CheckExact(BorrowedReference ob)
1103+
=> PyObject_TypeCheckExact(ob, PyBoolType);
10991104

11001105
internal static NewReference PyInt_FromInt32(int value) => PyLong_FromLongLong(value);
11011106

@@ -1141,6 +1146,8 @@ internal static NewReference PyLong_FromString(string value, int radix)
11411146

11421147
internal static bool PyFloat_Check(BorrowedReference ob)
11431148
=> PyObject_TypeCheck(ob, PyFloatType);
1149+
internal static bool PyFloat_CheckExact(BorrowedReference ob)
1150+
=> PyObject_TypeCheckExact(ob, PyFloatType);
11441151

11451152
/// <summary>
11461153
/// Return value: New reference.
@@ -1282,9 +1289,9 @@ internal static bool PyFloat_Check(BorrowedReference ob)
12821289
// Python string API
12831290
//====================================================================
12841291
internal static bool PyString_Check(BorrowedReference ob)
1285-
{
1286-
return PyObject_TYPE(ob) == PyStringType;
1287-
}
1292+
=> PyObject_TypeCheck(ob, PyStringType);
1293+
internal static bool PyString_CheckExact(BorrowedReference ob)
1294+
=> PyObject_TypeCheckExact(ob, PyStringType);
12881295

12891296
internal static NewReference PyString_FromString(string value)
12901297
{
@@ -1643,6 +1650,8 @@ internal static bool PyType_IsSubtype(BorrowedReference t1, BorrowedReference t2
16431650
return Delegates.PyType_IsSubtype(t1, t2);
16441651
}
16451652

1653+
internal static bool PyObject_TypeCheckExact(BorrowedReference ob, BorrowedReference tp)
1654+
=> PyObject_TYPE(ob) == tp;
16461655
internal static bool PyObject_TypeCheck(BorrowedReference ob, BorrowedReference tp)
16471656
{
16481657
BorrowedReference t = PyObject_TYPE(ob);

0 commit comments

Comments
 (0)