[Jython-checkins] jython: Adjusted PyGenerator such that str(generator_object) behaves like in CPython.
stefan.richthofer
jython-checkins at python.org
Mon Jan 9 17:31:32 EST 2017
https://hg.python.org/jython/rev/088c63ec3233
changeset: 8001:088c63ec3233
user: Stefan Richthofer <stefan.richthofer at gmx.de>
date: Mon Jan 09 23:31:07 2017 +0100
summary:
Adjusted PyGenerator such that str(generator_object) behaves like in CPython. Same for repr.
files:
Lib/test/test_genexps.py | 2 +-
src/org/python/core/PyGenerator.java | 10 ++++++++++
2 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/Lib/test/test_genexps.py b/Lib/test/test_genexps.py
--- a/Lib/test/test_genexps.py
+++ b/Lib/test/test_genexps.py
@@ -98,7 +98,7 @@
Verify that parenthesis are required when used as a keyword argument value
>>> dict(a = (i for i in xrange(10))) #doctest: +ELLIPSIS
- {'a': <generator object at ...>}
+ {'a': <generator object <genexpr> at ...>}
Verify early binding for the outermost for-expression
diff --git a/src/org/python/core/PyGenerator.java b/src/org/python/core/PyGenerator.java
--- a/src/org/python/core/PyGenerator.java
+++ b/src/org/python/core/PyGenerator.java
@@ -177,6 +177,16 @@
return result;
}
+ @Override
+ public String toString() {
+ return generator_toString();
+ }
+
+ @ExposedMethod(names = "__repr__")
+ final String generator_toString() {
+ return String.format("<generator object %s at %s>", getName(), Py.idstr(this));
+ }
+
/* Traverseproc implementation */
@Override
--
Repository URL: https://hg.python.org/jython
More information about the Jython-checkins
mailing list