| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f707698 commit 2e0874a
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,6 @@ This document follows the conventions laid out in [Keep a CHANGELOG][]. | |||
| 13 | 13 | - Added function that sets Py_NoSiteFlag to 1. | |
| 14 | 14 | - Added support for Jetson Nano. | |
| 15 | 15 | - Added support for __len__ for .NET classes that implement ICollection | |
| 16 | - - Added `object.GetRawPythonProxy() -> PyObject` extension method, that bypasses any conversions | ||
| 17 | 16 | - Added PythonException.Format method to format exceptions the same as traceback.format_exception | |
| 18 | 17 | ||
| 19 | 18 | ### Changed | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -91,7 +91,7 @@ static void TupleRoundtripGeneric<T, TTuple>() { | |||
| 91 | 91 | class ObjectToEncoderInstanceEncoder<T> : IPyObjectEncoder | |
| 92 | 92 | { | |
| 93 | 93 | 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); | ||
| 95 | 95 | } | |
| 96 | 96 | ||
| 97 | 97 | /// <summary> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,7 +51,7 @@ public void TestConvertDoubleToManaged( | |||
| 51 | 51 | public void RawListProxy() | |
| 52 | 52 | { | |
| 53 | 53 | var list = new List<string> {"hello", "world"}; | |
| 54 | - var listProxy = list.GetRawPythonProxy(); | ||
| 54 | + var listProxy = PyObject.FromManagedObject(list); | ||
| 55 | 55 | var clrObject = (CLRObject)ManagedType.GetManagedObject(listProxy.Handle); | |
| 56 | 56 | Assert.AreSame(list, clrObject.inst); | |
| 57 | 57 | } | |
@@ -60,7 +60,7 @@ public void RawListProxy() | |||
| 60 | 60 | public void RawPyObjectProxy() | |
| 61 | 61 | { | |
| 62 | 62 | var pyObject = "hello world!".ToPython(); | |
| 63 | - var pyObjectProxy = pyObject.GetRawPythonProxy(); | ||
| 63 | + var pyObjectProxy = PyObject.FromManagedObject(pyObject); | ||
| 64 | 64 | var clrObject = (CLRObject)ManagedType.GetManagedObject(pyObjectProxy.Handle); | |
| 65 | 65 | Assert.AreSame(pyObject, clrObject.inst); | |
| 66 | 66 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,7 @@ public PyObject TryEncode(object value) | |||
| 13 | 13 | { | |
| 14 | 14 | if (value is null) throw new ArgumentNullException(nameof(value)); | |
| 15 | 15 | ||
| 16 | - return value.GetRawPythonProxy(); | ||
| 16 | + return PyObject.FromManagedObject(value); | ||
| 17 | 17 | } | |
| 18 | 18 | ||
| 19 | 19 | public virtual bool CanEncode(Type type) => false; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -68,17 +68,5 @@ internal static IntPtr GetInstHandle(object ob) | |||
| 68 | 68 | CLRObject co = GetInstance(ob); | |
| 69 | 69 | return co.pyHandle; | |
| 70 | 70 | } | |
| 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 | - } | ||
| 83 | 71 | } | |
| 84 | 72 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -967,16 +967,5 @@ public static PyObject ToPython(this object o) | |||
| 967 | 967 | { | |
| 968 | 968 | return new PyObject(Converter.ToPython(o, o?.GetType())); | |
| 969 | 969 | } | |
| 970 | - | ||
| 971 | - /// <summary> | ||
| 972 | - /// Gets raw Python proxy for this object (bypasses all conversions, | ||
| 973 | - /// except <c>null</c> <==> <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 | - } | ||
| 981 | 970 | } | |
| 982 | 971 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -111,7 +111,8 @@ public IntPtr Handle | |||
| 111 | 111 | ||
| 112 | 112 | ||
| 113 | 113 | /// <summary> | |
| 114 | - /// FromManagedObject Method | ||
| 114 | + /// Gets raw Python proxy for this object (bypasses all conversions, | ||
| 115 | + /// except <c>null</c> <==> <c>None</c>) | ||
| 115 | 116 | /// </summary> | |
| 116 | 117 | /// <remarks> | |
| 117 | 118 | /// Given an arbitrary managed object, return a Python instance that | |
| Back | FazBrowse Home | New Git URL |
0 commit comments