8000 expose PyType.Get · pythonnet/pythonnet@0355ebc · GitHub
[go: up one dir, main page]

Skip to content

Commit 0355ebc

Browse files
committed
expose PyType.Get
1 parent 9b7dbae commit 0355ebc

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/runtime/pytype.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@ public PyType(TypeSpec spec, PyTuple? bases = null) : base(FromSpec(spec, bases)
1515
/// <summary>Wraps an existing type object.</summary>
1616
public PyType(PyObject o) : base(FromObject(o)) { }
1717

18+
internal PyType(PyType o)
19+
: base(o is not null ? o.Reference : throw new ArgumentNullException(nameof(o)))
20+
{
21+
}
22+
1823
internal PyType(BorrowedReference reference) : base(reference)
1924
{
2025
if (!Runtime.PyType_Check(this.Handle))
2126
throw new ArgumentException("object is not a type");
2227
}
2328

24-
internal PyType(StolenReference reference) : base(EnsureIsType(in reference))
29+
internal PyType(in StolenReference reference) : base(EnsureIsType(in reference))
2530
{
2631
}
2732

@@ -69,17 +74,15 @@ internal static bool IsType(BorrowedReference value)
6974

7075
/// <summary>
7176
/// Gets <see cref="PyType"/>, which represents the specified CLR type.
72-
/// Must be called after the CLR type was mapped to its Python type.
7377
/// </summary>
74-
internal static PyType Get(Type clrType)
78+
public static PyType Get(Type clrType)
7579
{
76-
if (clrType == null)
80+
if (clrType is null)
7781
{
7882
throw new ArgumentNullException(nameof(clrType));
7983
}
8084

81-
ClassBase pyClass = ClassManager.GetClass(clrType);
82-
return new PyType(pyClass.ObjectReference);
85+
return new PyType(TypeManager.GetType(clrType));
8386
}
8487

8588
internal BorrowedReference BaseReference

0 commit comments

Comments
 (0)
0