Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2cb16fe

Browse files
committed
when converting to object, wrap values of unknown type into PyObject instead of failing
This enables overload resolution with object parameters to behave the same way PyObject parameters behave - e.g. allow any Python object to be passed as PyObject as fallback. Resolves #811
1 parent 63ccb6b commit 2cb16fe

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
5454
- Reattach python exception traceback information (#545)
5555
- PythonEngine.Intialize will now call `Py_InitializeEx` with a default value of 0, so signals will not be configured by default on embedding. This is different from the previous behaviour, where `Py_Initialize` was called instead, which sets initSigs to 1. ([#449][i449])
5656
- Refactored MethodBinder.Bind in preparation to make it extensible (#829)
57+
- When calling C# from Python, enable passing argument of any type to a parameter of C# type `object` by wrapping it into `PyObject` instance. ([#881][i881])
5758
- Look for installed Windows 10 sdk's during installation instead of relying on specific versions.
5859

5960
### Fixed

src/runtime/converter.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,12 +382,9 @@ internal static bool ToManagedValue(IntPtr value, Type obType,
382382
return ToArray(value, typeof(object[]), out result, setError);
383383
}
384384

385-
if (setError)
386-
{
387-
Exceptions.SetError(Exceptions.TypeError, "value cannot be converted to Object");
388-
}
389-
390-
return false;
385+
Runtime.XIncref(value); // PyObject() assumes ownership
386+
result = new PyObject(value);
387+
return true;
391388
}
392389

393390
// Conversion to 'Type' is done using the same mappings as above for objects.

0 commit comments

Comments
 (0)