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

Skip to content

Commit 79e34bc

Browse files
committed
PyObject.GetPythonType returns PyType
1 parent d48f512 commit 79e34bc

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/runtime/pyobject.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,10 @@ internal BorrowedReference GetPythonTypeReference()
237237
/// Returns the Python type of the object. This method is equivalent
238238
/// to the Python expression: type(object).
239239
/// </remarks>
240-
public PyObject GetPythonType()
240+
public PyType GetPythonType()
241241
{
242-
IntPtr tp = Runtime.PyObject_Type(obj);
243-
return new PyObject(tp);
242+
var tp = Runtime.PyObject_TYPE(Reference);
243+
return new PyType(tp, prevalidated: true);
244244
}
245245

246246

src/runtime/pytype.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ internal PyType(PyType o)
2020
{
2121
}
2222

23-
internal PyType(BorrowedReference reference) : base(reference)
23+
internal PyType(BorrowedReference reference, bool prevalidated = false) : base(reference)
2424
{
25+
if (prevalidated) return;
26+
2527
if (!Runtime.PyType_Check(this.Handle))
2628
throw new ArgumentException("object is not a type");
2729
}

0 commit comments

Comments
 (0)