Issue2105
Created on 2013-11-30.13:50:42 by richardfearn, last changed 2015-04-27.01:52:52 by zyasoft.
File name |
Uploaded |
Description |
Edit |
Remove |
issue2105.py
|
richardfearn,
2013-11-30.13:59:44
|
Test program |
|
|
msg8183 (view) |
Author: Richard Fearn (richardfearn) |
Date: 2013-11-30.13:50:40 |
|
Inconsistent conversion of PyObject to String in StdoutWrapper
Given some object o, executing
print o
causes Jython to build a string representation of o to be displayed on the console.
The conversion is done differently depending on whether stdout/stderr are accessed through a PyFile or a PyFileWriter.
Jython uses PyFile by default, and results in an object's __str__ method being called.
PyFileWriter causes an object's __repr__ method to be called instead, which is inconsistent with CPython.
|
msg8184 (view) |
Author: Richard Fearn (richardfearn) |
Date: 2013-11-30.13:59:44 |
|
Running the test program using CPython (2.7.5 in this case) shows an object's __str__ method is called:
$ python issue2105.py
str
Running with Jython 2.5.3 or the trunk also shows the __str__ method being called:
$ jython issue2105.py
str
so out of the box, Jython is consistent with CPython.
But if stdout/stderr are changed to point to a Writer, so that Jython uses a PyFileWriter, for example by changing jython.java to:
InteractiveConsole interp = new InteractiveConsole();
interp.setOut(new PrintWriter(System.out));
interp.setErr(new PrintWriter(System.err));
then the __repr__ method is called instead:
$ jython issue2105.py
repr
|
msg8185 (view) |
Author: Richard Fearn (richardfearn) |
Date: 2013-11-30.14:02:49 |
|
On the trunk, the print method in StdoutWrapper calls printToFile if stdout is a PyFile, and calls printToFileWriter if stdout is a PyFileWriter.
printToFile does this:
s = o.__str__().toString();
whereas printToFileWriter does this:
s = o.toString();
which leads to the __repr__ method being called.
It's unclear why printToFileWriter doesn't also invoke the __str__ method.
|
msg8347 (view) |
Author: Jonathan Blakes (qny31541) |
Date: 2014-05-08.14:52:51 |
|
Submitted Bitbucket pull request: https://bitbucket.org/jython/jython/pull-request/32/2105-fix-inconsistent-conversion-of/diff
|
msg9335 (view) |
Author: Jim Baker (zyasoft) |
Date: 2015-01-07.07:08:18 |
|
Need to commit the outstanding PR attached to this bug, it's been too long!
|
msg9892 (view) |
Author: Jim Baker (zyasoft) |
Date: 2015-04-19.20:47:44 |
|
Fixed as of https://hg.python.org/jython/rev/fbcbd5f9462b
Made it in 2.7.0 after all
|
|
Date |
User |
Action |
Args |
2015-04-27 01:52:52 | zyasoft | set | status: pending -> closed |
2015-04-19 20:47:44 | zyasoft | set | status: open -> pending resolution: fixed milestone: Jython 2.7.1 -> Jython 2.7.0 messages:
+ msg9892 versions:
- Jython 2.5 |
2015-04-15 20:44:50 | zyasoft | set | milestone: Jython 2.7.1 |
2015-01-07 07:08:18 | zyasoft | set | priority: high assignee: zyasoft messages:
+ msg9335 nosy:
+ zyasoft |
2014-05-08 14:52:52 | qny31541 | set | nosy:
+ qny31541 messages:
+ msg8347 |
2013-11-30 14:02:49 | richardfearn | set | messages:
+ msg8185 |
2013-11-30 13:59:44 | richardfearn | set | files:
+ issue2105.py messages:
+ msg8184 |
2013-11-30 13:50:42 | richardfearn | create | |
|