8000 respond to PR feedback · pythonnet/pythonnet@bf2d038 · GitHub
[go: up one dir, main page]

Skip to content

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

8000
Appearance settings

Commit bf2d038

Browse files
committed
respond to PR feedback
1 parent 085c665 commit bf2d038

File tree

5 files changed

+7
-28
lines changed

5 files changed

+7
-28
lines changed

src/embed_tests/Codecs.cs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -98,34 +98,12 @@ static void TupleRoundtripGeneric<T, TTuple>()
9898
}
9999
}
100100

101-
static string GetIntIterableCommands(string instanceName)
102-
{
103-
var builder = new System.Text.StringBuilder();
104-
builder.AppendLine(@"
105-
class foo():
106-
def __init__(self):
107-
self.counter = 0
108-
def __iter__(self):
109-
return self
110-
def __next__(self):
111-
if self.counter == 3:
112-
raise StopIteration
113-
self.counter = self.counter + 1
114-
return self.counter");
115-
116-
builder.AppendLine(instanceName + " = foo()");
117-
return builder.ToString();
118-
}
119-
120101
static PyObject GetPythonIterable()
121102
{
122-
var locals = new PyDict();
123103
using (Py.GIL())
124104
{
125-
PythonEngine.Exec(GetIntIterableCommands("foo_instance"), null, locals.Handle);
105+
return PythonEngine.Eval("map(lambda x: x, [1,2,3])");
126106
}
127-
128-
return locals.GetItem("foo_instance");
129107
}
130108

131109
[Test]

src/runtime/Codecs/IterableDecoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal static bool IsIterable(Type targetType)
1919

2020
internal static bool IsIterable(PyObject objectType)
2121
{
22-
return objectType.HasAttr("__iter__");
22+
return Runtime.PyIter_Check(objectType.Handle);
2323
}
2424

2525
public bool CanDecode(PyObject objectType, Type targetType)

src/runtime/Codecs/ListDecoder.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ private static bool IsList(Type targetType)
1515

1616
private static bool IsList(PyObject objectType)
1717
{
18+
//TODO accept any python object that implements the sequence and list protocols
1819
//must implement sequence protocol to fully implement list protocol
19-
if (!SequenceDecoder.IsSequence(objectType)) return false;
20+
//if (!SequenceDecoder.IsSequence(objectType)) return false;
2021

21-
//returns wheter the type is a list.
22+
//returns wheter the type is a list.
2223
return objectType.Handle == Runtime.PyListType;
2324
}
2425

src/runtime/CollectionWrappers/IterableWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public IterableWrapper(PyObject pyObj)
1212
{
1313
if (pyObj == null)
1414
throw new ArgumentNullException();
15-
pyObject = pyObj;
15+
pyObject = new PyObject(pyObj.Reference);
1616
}
1717

1818
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

src/runtime/CollectionWrappers/SequenceWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public int Count
1414
{
1515
get
1616
{
17-
var size = Runtime.PySequence_Size(pyObject.Handle);
17+
var size = Runtime.PySequence_Size(pyObject.Reference);
1818
if (size == -1)
1919
{
2020
Runtime.CheckExceptionOccurred();

0 commit comments

Comments
 (0)
0