Skip to content

Commit 2e0874a

Browse files
authored
Removes new object.GetRawPythonProxy extension method in favor of existing PyObject.FromManagedObject (#1132)
Reverts most of #1078
1 parent f707698 commit 2e0874a

File tree

7 files changed

+6
-29
lines changed

7 files changed

+6
-29
lines changed

CHANGELOG.md

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
1313
- Added function that sets Py_NoSiteFlag to 1.
1414
- Added support for Jetson Nano.
1515
- Added support for __len__ for .NET classes that implement ICollection
16-
- Added `object.GetRawPythonProxy() -> PyObject` extension method, that bypasses any conversions
1716
- Added PythonException.Format method to format exceptions the same as traceback.format_exception
1817

1918
### Changed

src/embed_tests/Codecs.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static void TupleRoundtripGeneric<T, TTuple>() {
9191
class ObjectToEncoderInstanceEncoder<T> : IPyObjectEncoder
9292
{
9393
public bool CanEncode(Type type) => type == typeof(T);
94-
public PyObject TryEncode(object value) => this.GetRawPythonProxy();
94+
public PyObject TryEncode(object value) => PyObject.FromManagedObject(this);
9595
}
9696

9797
/// <summary>

src/embed_tests/TestConverter.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void TestConvertDoubleToManaged(
5151
public void RawListProxy()
5252
{
5353
var list = new List<string> {"hello", "world"};
54-
var listProxy = list.GetRawPythonProxy();
54+
var listProxy = PyObject.FromManagedObject(list);
5555
var clrObject = (CLRObject)ManagedType.GetManagedObject(listProxy.Handle);
5656
Assert.AreSame(list, clrObject.inst);
5757
}
@@ -60,7 +60,7 @@ public void RawListProxy()
6060
public void RawPyObjectProxy()
6161
{
6262
var pyObject = "hello world!".ToPython();
63-
var pyObjectProxy = pyObject.GetRawPythonProxy();
63+
var pyObjectProxy = PyObject.FromManagedObject(pyObject);
6464
var clrObject = (CLRObject)ManagedType.GetManagedObject(pyObjectProxy.Handle);
6565
Assert.AreSame(pyObject, clrObject.inst);
6666

src/runtime/Codecs/RawProxyEncoder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public PyObject TryEncode(object value)
1313
{
1414
if (value is null) throw new ArgumentNullException(nameof(value));
1515

16-
return value.GetRawPythonProxy();
16+
return PyObject.FromManagedObject(value);
1717
}
1818

1919
public virtual bool CanEncode(Type type) => false;

src/runtime/clrobject.cs

-12
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,5 @@ internal static IntPtr GetInstHandle(object ob)
6868
CLRObject co = GetInstance(ob);
6969
return co.pyHandle;
7070
}
71-
72-
/// <summary>
73-
/// Creates <see cref="CLRObject"/> proxy for the given object,
74-
/// and returns a <see cref="NewReference"/> to it.
75-
/// </summary>
76-
internal static NewReference MakeNewReference(object obj)
77-
{
78-
if (obj is null) throw new ArgumentNullException(nameof(obj));
79-
80-
// TODO: CLRObject currently does not have Dispose or finalizer which might change in the future
81-
return NewReference.DangerousFromPointer(GetInstHandle(obj));
82-
}
8371
}
8472
}

src/runtime/converter.cs

-11
Original file line numberDiff line numberDiff line change
@@ -967,16 +967,5 @@ public static PyObject ToPython(this object o)
967967
{
968968
return new PyObject(Converter.ToPython(o, o?.GetType()));
969969
}
970-
971-
/// <summary>
972-
/// Gets raw Python proxy for this object (bypasses all conversions,
973-
/// except <c>null</c> &lt;==&gt; <c>None</c>)
974-
/// </summary>
975-
public static PyObject GetRawPythonProxy(this object o)
976-
{
977-
if (o is null) return new PyObject(new BorrowedReference(Runtime.PyNone));
978-
979-
return CLRObject.MakeNewReference(o).MoveToPyObject();
980-
}
981970
}
982971
}

src/runtime/pyobject.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ public IntPtr Handle
111111

112112

113113
/// <summary>
114-
/// FromManagedObject Method
114+
/// Gets raw Python proxy for this object (bypasses all conversions,
115+
/// except <c>null</c> &lt;==&gt; <c>None</c>)
115116
/// </summary>
116117
/// <remarks>
117118
/// Given an arbitrary managed object, return a Python instance that

0 commit comments

Comments
 (0)