Menu

#25 Add better support for conversion to native Python types in public API

Unstable_(example)
open
nobody
None
5
2013-09-26
2013-09-26
No

The attached patch improves support for converting managed values (reference or boxed values) to the corresponding Python types.

This support had previously been partly implemented in Converter.ToPython() but it was not exposed in the public interface of PyObject (if I'm not mistaken), which made it hard for me to call Python functions from managed code in an embedding scenario. My patch makes the following changes:

  • adds PyObject.FromManagedValue() which tries to convert a given managed object to an appropriate builtin Python type
  • adds Converter.ToPythonValue() which does the same thing as Converter.ToPython() except that it converts managed arrays to Python lists where appropriate

Being not very familiar with the Python for .NET codebase, I didn't have the heart to build my array support directly into Converter.ToPython(). However I'd be happy if the array handling code could go to Converter.ToPython() in order to avoid having two similarly-named functions (.ToPython() and .ToPythonValue()) which differ in a non-obvious way, so if that is considered appropriate, please move it there.

1 Attachments

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.