Skip to content

Inconsistent Conversion of Sequence Types #909

Closed
@rmadsen-ks

Description

@rmadsen-ks

Environment

  • Pythonnet version: 2.4 (build from df0574d)
  • Python version: 2.7, 3.6, 3.7
  • Operating System: Windows 10

Details

I am trying to convert from List to PyList and back without losing type information.

            // this works:
            int[] values2 = new int[] { 1, 2, 3 };
            var pyvalues2 = values2.ToPython();
            pyvalues2.As<int[]>();

            // this does not work.
            List<int> values = new List<int> { 1, 2, 3 };
            var pyvalues = values.ToPython();
            pyvalues.As<List<int>>(); // unable to convert back to List<int>

It seems ToPython will just take any IEnumerable or IList and turn it into a python list. Even though it is not generally possible to convert it back. In this case I'd rather keep it as the original type, because eventually I'll need to get it back to C#.

I understand why the current behavior makes things easier, but it would be great if it was possible to disable or alter this behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions