You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But, I encountered a Transcrypted code modifying the argument x in sorted(x):
print('cups.x= ', [c.mesh.position.x for c in cups])
cupClosest= sorted(cups, key=lambda cup: cup.mesh.position.subtract(posLocal).length())[0]
print('cups.x(after sorted())= ', [c.mesh.position.x for c in cups])
The sorted() method call the copy() method
And the copy() method contains :
export function copy (anObject) {
if (anObject == null || typeof anObject == "object") {
return anObject;
} else {
var result = {};
for (var attrib in obj) {
if (anObject.hasOwnProperty (attrib)) {
result [attrib] = anObject [attrib];
}
}
return result;
}
}
It's bugged
If it's an object (an array in your case) it return the object. So useless for a copy method.
Otherwise an error occur because "obj" is not know in the loop
The copy method must be something like :
export function copy (anObject) {
if (anObject == null || typeof anObject != "object") {
return anObject;
}
else {
if (anObject instanceof Array){
var res = []
for(var elem of anObject){
res.push(elem)
}
return res
}else{
var result = {};
for (var attrib in anObject) {
if (anObject.hasOwnProperty (attrib)) {
result [attrib] = anObject [attrib];
}
}
return result;
}
}
}
The copy function that sorted is using has been re-implemented as part of the new copy module in dev_3.9.3 branch to be released in v3.9.3
It should work in most cases, but needs a bit more testing.
Activity
[-]sorted(x) changes the argument x (bug?)[/-][+]sorted(x) modifies the argument x (bug?)[/+]Iv3li0s commentedon May 3, 2024
The sorted() method call the copy() method
And the copy() method contains :
It's bugged
If it's an object (an array in your case) it return the object. So useless for a copy method.
Otherwise an error occur because "obj" is not know in the loop
The copy method must be something like :
JennaSys commentedon Jul 6, 2024
The
copyfunction thatsortedis using has been re-implemented as part of the newcopymodule in dev_3.9.3 branch to be released in v3.9.3It should work in most cases, but needs a bit more testing.
JennaSys commentedon Jul 17, 2024
Merged to master on PR #876