-
Notifications
You must be signed in to change notification settings - Fork 762
Added ToPythonAs()
extension method for explicit conversion using an arbitrary type
#2419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
1ef1e7b
255201a
37c4d04
4fbf04c
cf8ff1f
bc11136
1073b03
b5a18d1
37ec583
ad7f985
bac598f
e04b6c4
8bb7519
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ public partial class PyObject : DynamicObject, IDisposable, ISerializable | |
/// Trace stack for PyObject's construction | ||
/// </summary> | ||
public StackTrace Traceback { get; } = new StackTrace(1); | ||
#endif | ||
#endif | ||
|
||
protected IntPtr rawPtr = IntPtr.Zero; | ||
internal readonly int run = Runtime.GetRun(); | ||
|
@@ -136,14 +136,14 @@ public IntPtr Handle | |
/// Given an arbitrary managed object, return a Python instance that | ||
/// reflects the managed object. | ||
/// </remarks> | ||
public static PyObject FromManagedObject(object ob) | ||
public static PyObject FromManagedObject(object ob, Type? type = null) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need a use case and a test for this change as well. Also, you have to add a separate overload because AFAIK adding default arguments breaks binary compatibility (e.g. libs compiled prior to this change will fail with |
||
// Special case: if ob is null, we return None. | ||
if (ob == null) | ||
{ | ||
return new PyObject(Runtime.PyNone); | ||
} | ||
return CLRObject.GetReference(ob).MoveToPyObject(); | ||
return CLRObject.GetReference(ob, type ?? ob.GetType()).MoveToPyObject(); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -235,7 +235,7 @@ public void Dispose() | |
{ | ||
GC.SuppressFinalize(this); | ||
Dispose(true); | ||
|
||
} | ||
|
||
internal StolenReference Steal() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows anyone that has recent versions of .net to run these tests. I can revert but I think its usefull, otherwise one needs to install .net6 which is already deprecated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be conditioned on not running in CI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any config/env var which I can check?