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

Skip to content

Commit ad36031

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 7daa47f commit ad36031

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
5858
- Reattach python exception traceback information (#545)
5959
- 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])
6060
- Refactored MethodBinder.Bind in preparation to make it extensible (#829)
61+
- 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])
6162
- Look for installed Windows 10 sdk's during installation instead of relying on specific versions.
6263

6364
### Fixed

src/runtime/converter.cs

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

401-
if (setError)
402-
{
403-
Exceptions.SetError(Exceptions.TypeError, "value cannot be converted to Object");
404-
}
405-
406-
return false;
401+
Runtime.XIncref(value); // PyObject() assumes ownership
402+
result = new PyObject(value);
403+
return true;
407404
}
408405

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

0 commit comments

Comments
 (0)