FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Removes new object.GetRawPythonProxy extension method by lostmsu · Pull Request #1132 · pythonnet/pythonnet · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cs  (6) .md  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 0 additions & 1 deletion CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
- Added function that sets Py_NoSiteFlag to 1.
- Added support for Jetson Nano.
- Added support for __len__ for .NET classes that implement ICollection
- Added `object.GetRawPythonProxy() -> PyObject` extension method, that bypasses any conversions
- Added PythonException.Format method to format exceptions the same as traceback.format_exception

### Changed
Expand Down
2 changes: 1 addition & 1 deletion src/embed_tests/Codecs.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static void TupleRoundtripGeneric<T, TTuple>() {
class ObjectToEncoderInstanceEncoder<T> : IPyObjectEncoder
{
public bool CanEncode(Type type) => type == typeof(T);
public PyObject TryEncode(object value) => this.GetRawPythonProxy();
public PyObject TryEncode(object value) => PyObject.FromManagedObject(this);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/embed_tests/TestConverter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void TestConvertDoubleToManaged(
public void RawListProxy()
{
var list = new List<string> {"hello", "world"};
var listProxy = list.GetRawPythonProxy();
var listProxy = PyObject.FromManagedObject(list);
var clrObject = (CLRObject)ManagedType.GetManagedObject(listProxy.Handle);
Assert.AreSame(list, clrObject.inst);
}
Expand All @@ -60,7 +60,7 @@ public void RawListProxy()
public void RawPyObjectProxy()
{
var pyObject = "hello world!".ToPython();
var pyObjectProxy = pyObject.GetRawPythonProxy();
var pyObjectProxy = PyObject.FromManagedObject(pyObject);
var clrObject = (CLRObject)ManagedType.GetManagedObject(pyObjectProxy.Handle);
Assert.AreSame(pyObject, clrObject.inst);

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/Codecs/RawProxyEncoder.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public PyObject TryEncode(object value)
{
if (value is null) throw new ArgumentNullException(nameof(value));

return value.GetRawPythonProxy();
return PyObject.FromManagedObject(value);
}

public virtual bool CanEncode(Type type) => false;
Expand Down
12 changes: 0 additions & 12 deletions src/runtime/clrobject.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,5 @@ internal static IntPtr GetInstHandle(object ob)
CLRObject co = GetInstance(ob);
return co.pyHandle;
}

/// <summary>
/// Creates <see cref="CLRObject"/> proxy for the given object,
/// and returns a <see cref="NewReference"/> to it.
/// </summary>
internal static NewReference MakeNewReference(object obj)
{
if (obj is null) throw new ArgumentNullException(nameof(obj));

// TODO: CLRObject currently does not have Dispose or finalizer which might change in the future
return NewReference.DangerousFromPointer(GetInstHandle(obj));
}
}
}
11 changes: 0 additions & 11 deletions src/runtime/converter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -967,16 +967,5 @@ public static PyObject ToPython(this object o)
{
return new PyObject(Converter.ToPython(o, o?.GetType()));
}

/// <summary>
/// Gets raw Python proxy for this object (bypasses all conversions,
/// except <c>null</c> &lt;==&gt; <c>None</c>)
/// </summary>
public static PyObject GetRawPythonProxy(this object o)
{
if (o is null) return new PyObject(new BorrowedReference(Runtime.PyNone));

return CLRObject.MakeNewReference(o).MoveToPyObject();
}
}
}
3 changes: 2 additions & 1 deletion src/runtime/pyobject.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public IntPtr Handle


/// <summary>
/// FromManagedObject Method
/// Gets raw Python proxy for this object (bypasses all conversions,
/// except <c>null</c> &lt;==&gt; <c>None</c>)
/// </summary>
/// <remarks>
/// Given an arbitrary managed object, return a Python instance that
Expand Down

Back | FazBrowse Home | New Git URL