Skip to content

Retry: Enable C# parameters of type object accept any argument, passed from Python #889

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

Merged
merged 6 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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
  • Loading branch information
lostmsu committed Feb 27, 2020
commit ad360311c05e2b750ea53631b46ddae3ee82f5c8
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
- Reattach python exception traceback information (#545)
- 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])
- Refactored MethodBinder.Bind in preparation to make it extensible (#829)
- 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])
- Look for installed Windows 10 sdk's during installation instead of relying on specific versions.

### Fixed
Expand Down
9 changes: 3 additions & 6 deletions src/runtime/converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,9 @@ internal static bool ToManagedValue(IntPtr value, Type obType,
return ToArray(value, typeof(object[]), out result, setError);
}

if (setError)
{
Exceptions.SetError(Exceptions.TypeError, "value cannot be converted to Object");
}

return false;
Runtime.XIncref(value); // PyObject() assumes ownership
result = new PyObject(value);
return true;
}

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