-
Notifications
You must be signed in to change notification settings - Fork 635
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
Decode Python list into IList in function calls #10865
Conversation
Adds tests for the following conversion scenarios: - Python list => .NET IList (CPython fails) - .NET array => Python list - Python tuple => .NET array - Python tuple => .NET IList (CPython fails) - Python range => .NET array - Python range => .NET IList (CPython fails) - Python dict => .NET IDictionary (CPython fails) - .NET IDictionary => Python dict (CPython unkonwn) Also commented out some tests that fail in both engines but may be considered to fix in CPython: - .NET IList => Python list - Python array => .NET IList - Python dict => DS Dictionary Other types considered but not added as tests: - classes (can't convert them) - dictionary view objects (uncommon) - bytes, bytearray, memoryview (uncommon) - set, frozenset (uncommon) - complex (uncommon)
return false; | ||
} | ||
|
||
using (var pyList = PyList.AsList(pyObj)) |
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.
I'm confused by this using statement, does AsList
return a .net list or a Python List?
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 a Python list
{ | ||
// This is a no-op to prevent Python.NET from encoding generic lists | ||
// https://github.com/pythonnet/pythonnet/pull/963#issuecomment-642938541 | ||
return PyObject.FromManagedObject(value); |
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.
does this break examples where I want to call a python function with a list of ints?
def sum(data):
for i in data:
where data is a .net List<int>
?
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.
Good question. Let me try it and come back with the answer.
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.
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.
sure, nothing wrong with more tests?
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.
okay, so l2 is a .net list because Flatten is a zt function?
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, it's List.Flatten
from our core nodes
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.
This looks good @mmisol - I would like to get the tests passing soon though - need to check with @alfredo-pozo on that.
The build passed here https://master-15.jenkins.autodesk.com/view/DYN/job/DYN-DevCI_Self_Service/695/. Merging |
Purpose
Implements a decoder for Python sequence to transform them into generic
or non-generic IList. This relies on Python.NET 'PySequence.ToList'.
Also implements an encoder to perform a 'no-op'. This allows to treat
returned lists from function calls like .NET lists, which is the
behavior of Iron Python.
Declarations
Check these if you believe they are true
*.resx
filesReviewers
@DynamoDS/dynamo