8000 PyObject.GetPythonType returns PyType · pythonnet/pythonnet@79e34bc · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

8000
Appearance settings

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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 1 deletion
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)
0