Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

List conversion fails on new version of pythonnet compared to 3.0.0.post1 #2004

Open
@screig

Description

@screig

Environment

  • Pythonnet version:
    Works with pythonnet==3.0.0.post1
    Failes with pythonnet>=3.0.0.post1

  • Python version:
    Python 3.8.0

  • Operating System:
    Windows

  • .NET Runtime:
    netstandard2.0;net471

Details

I followed the notes to write a codec to convert a C# List to a Python list, here it is:

  /// <summary>   /// This class will convert a C# list of strings to a Python list [] of strings.   /// </summary>   public class ListStringConversions : IPyObjectEncoder   {       bool IPyObjectEncoder.CanEncode(Type type)       {           return type == typeof(IList<string>);       }       PyObject IPyObjectEncoder.TryEncode(object value)       {           using (var scope = Py.CreateScope())           {               scope.Exec($"a = []");               var input = (List<string>)value;               foreach (var item in input)                   scope.Exec($"a.append('{item}')");  // {item}               return scope.Get("a");           }       }   }

I have a simple test which calls in to a C# assembly and returns a list. With pythonnet version 3.0.0.post1, the C# list is successfully converted to a python list.

In my requirements file, I had this
pythonnet>=3.0.0.post1

Now on the CICD process it has updated the pythonnet package and the same test fails:

>       assert isinstance(codes, list)E       assert FalseE        +  where False = isinstance(<System.Collections.Generic.IList[String] object at 0x0000023C1D9D5180>, list)

The code no longer is returning a python list. I switched the requirements file to
pythonnet==3.0.0.post1

and the test passes. As such I think there is a breaking change in the latest release that prevents the conversions been executed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp