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

Drop List and IEnumerable conversions#963

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Show file tree
Hide file tree
Changes fromall commits
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
37 changes: 3 additions & 34 deletionssrc/runtime/converter.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -135,22 +135,6 @@ internal static IntPtr ToPython(object value, Type type)
return result;
}

if (value is IList && !(value is INotifyPropertyChanged) && value.GetType().IsGenericType)
{
using (var resultlist = new PyList())
{
foreach (object o in (IEnumerable)value)
{
using (var p = new PyObject(ToPython(o, o?.GetType())))
{
resultlist.Append(p);
}
}
Runtime.XIncref(resultlist.Handle);
return resultlist.Handle;
}
}

// it the type is a python subclass of a managed type then return the
// underlying python object rather than construct a new wrapper object.
var pyderived = value as IPythonDerivedType;
Expand All@@ -171,7 +155,7 @@ internal static IntPtr ToPython(object value, Type type)
// type is. we'd rather have the object bound to the actual
// implementing class.

type = value.GetType();
type =type ??value.GetType();

TypeCode tc = Type.GetTypeCode(type);

Expand DownExpand Up@@ -231,21 +215,6 @@ internal static IntPtr ToPython(object value, Type type)
return Runtime.PyLong_FromUnsignedLongLong((ulong)value);

default:
if (value is IEnumerable)
{
using (var resultlist = new PyList())
{
foreach (object o in (IEnumerable)value)
{
using (var p = new PyObject(ToPython(o, o?.GetType())))
{
resultlist.Append(p);
}
}
Runtime.XIncref(resultlist.Handle);
return resultlist.Handle;
}
}
result = CLRObject.GetInstHandle(value, type);
return result;
}
Expand DownExpand Up@@ -862,7 +831,7 @@ private static bool ToArray(IntPtr value, Type obType, out object result, bool s

var listType = typeof(List<>);
var constructedListType = listType.MakeGenericType(elementType);
IList list = IsSeqObj ? (IList) Activator.CreateInstance(constructedListType, new Object[] {(int) len}) :
IList list = IsSeqObj ? (IList) Activator.CreateInstance(constructedListType, new Object[] {(int) len}) :
(IList) Activator.CreateInstance(constructedListType);
IntPtr item;

Expand All@@ -883,7 +852,7 @@ private static bool ToArray(IntPtr value, Type obType, out object result, bool s

items = Array.CreateInstance(elementType, list.Count);
list.CopyTo(items, 0);

result = items;
return true;
}
Expand Down
11 changes: 10 additions & 1 deletionsrc/runtime/iterator.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
using System.Linq;
using System;
using System.Collections;

Expand All@@ -10,10 +11,18 @@ namespace Python.Runtime
internal class Iterator : ExtensionType
{
private IEnumerator iter;
private Type type;

public Iterator(IEnumerator e)
{
iter = e;

var genericType = e.GetType().GetInterfaces().FirstOrDefault(
x => x.IsGenericType &&
x.GetGenericTypeDefinition() == typeof(System.Collections.Generic.IEnumerator<>)
);

type = genericType?.GetGenericArguments().FirstOrDefault();
}


Expand DownExpand Up@@ -41,7 +50,7 @@ public static IntPtr tp_iternext(IntPtr ob)
return IntPtr.Zero;
}
object item = self.iter.Current;
return Converter.ToPythonImplicit(item);
return Converter.ToPython(item, self.type);
}

public static IntPtr tp_iter(IntPtr ob)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp