-
Notifications
You must be signed in to change notification settings - Fork 636
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert Python iterable to IList and IEnumerable #10879
Conversation
Adds support to convert any Python iterable to a list in the context of a function call using the CPython engine. The support is added by relaxing the check in the custom decoder to allow any iterable to come through, not only sequences. This should now allow converting dictionary view types, set and frozenset.
@@ -66,21 +68,29 @@ import clr | |||
|
|||
l3 = [[1,2],[3,4]] | |||
# Python list (nested) => .NET IList<IList<>> | |||
flatennedList = List.Flatten(l3) | |||
flattenedList = List.Flatten(l3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch
{ "one", 1 }, { "two", 2 }, { "three", 3 }, { "four", 4 } | ||
}; | ||
var expectedKeys = new List<string> { "one", "three", "two" }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it because List
unordered so sequence does not matter here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The order is alphabetic
|
||
dk = List.AddItemToEnd('four', d.keys()) | ||
dv = List.AddItemToEnd(4, d.values()) | ||
di = List.AddItemToEnd(('four', 4), d.items()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we get all this supported by simply adding the IsIterable
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. They were all iterable, but we were checking if they were sequences, which they are not. Since our Python.NET code supported all iterables we are good!
from DSCore import List | ||
|
||
s = { 'hello' } | ||
fs = frozenset(s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is a frozenset?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's like an immutable set.
Got the usual 23 failures related to the visualization tests. Should this be good to go @QilongTang ? |
@mmisol Sure go for it |
Purpose
Adds support to convert any Python iterable to an IList or IEnumerable
in the context of a function call using the CPython engine. The decoder
now checks if the PyObject returned is iterable instead of a sequence,
which is supported by the function we are using in Python.NET. Also,
IEnumerable, both generic and non-generic, is declared as a target type
to allow more conversion scenarios.
This should now allow converting dictionary view types, set and
frozenset to IList. It should also allow these and any other types that
are iterable (list, tuple, dictionary) to be converted to IEnumerable.
Declarations
Check these if you believe they are true
*.resx
filesReviewers
@mjkkirschner
FYIs
@DynamoDS/dynamo