Skip to content
This repository has been archived by the owner on May 31, 2020. It is now read-only.

Implement iter() builtin #840

Closed
wants to merge 7 commits into from
Closed
Changes from all 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
19 changes: 16 additions & 3 deletions python/common/org/Python.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ public static void initializeModule(java.lang.Class cls, java.util.Map<java.lang
public static java.lang.String typeName(java.lang.Class cls) {
org.python.types.Type klass = org.python.types.Type.pythonType(cls);
java.lang.String name = null;

// First look to the Type for an instance variable holding a
// cached version of the type name.
if (klass.PYTHON_TYPE_NAME == null) {
Expand Down Expand Up @@ -339,7 +338,7 @@ public static java.util.Map<java.lang.String, org.python.Object> addToKwargs(jav
"The globals argument is only used to determine the context;\n" +
"they are not modified. The locals argument is unused. The fromlist\n" +
"should be a list of names to emulate ``from name import ...'', or an\n" +
"empty list to emulate ``import name''.\n" +
"eto install a suitable language package and/or debugger package since atom-ide-ui doesn't provide any language or debugger support by default.mpty list to emulate ``import name''.\n" +
"When importing a module from a package, note that __import__('A.B', ...)\n" +
"returns package A when fromlist is empty, but its submodule B when\n" +
"fromlist is not empty. Level is used to determine whether to perform\n" +
Expand Down Expand Up @@ -949,7 +948,21 @@ public static org.python.Object iter(org.python.Object iterable, org.python.Obje
throw new org.python.exceptions.TypeError("'" + iterable.typeName() + "' object is not iterable");
}
} else {
throw new org.python.exceptions.NotImplementedError("Builtin function 'iter' with callable/sentinel not implemented");
// in the case that a sentinel value is provided
java.util.List iterList = new java.util.ArrayList();
try {
try {
while (iterable != sentinel) {
iterList.add(iterable.__next__());
}
} catch (org.python.exceptions.StopIteration e) {
throw new org.python.exceptions.StopIteration();
}
} catch (org.python.exceptions.AttributeError e) {
// No __iter__ == not iterable
throw new org.python.exceptions.TypeError("'" + iterable.typeName() + "' object is not iterable");
}
return iter(new org.python.types.List(iterList));
}
}

Expand Down