-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
doctest work with Windows PyReadline #44902
Comments
|
doctest crashes when working with Windows PyReadline (PyReadline is a component of Windows IPython) PyReadline expects "_SpoofOut" to have an "encoding" attribute E Traceback (most recent call last):
File "test_freecell_solver.py", line 26, in testDocTest
r = doctest.testmod(freecell_solver)
File "c:\Python25\Lib\doctest.py", line 1799, in testmod
runner.run(test)
File "c:\Python25\Lib\doctest.py", line 1335, in run
self.debugger = _OutputRedirectingPdb(save_stdout)
File "c:\Python25\Lib\doctest.py", line 320, in __init__
pdb.Pdb.__init__(self, stdout=out)
File "c:\Python25\Lib\pdb.py", line 66, in __init__
import readline
File "C:\Python25\Lib\site-packages\readline.py", line 5, in <module>
from pyreadline import *
File "C:\Python25\Lib\site-packages\pyreadline\__init__.py", line 10, in <module>
from rlmain import *
File "C:\Python25\Lib\site-packages\pyreadline\rlmain.py", line 13, in <module>
import clipboard,logger,console
File "C:\Python25\Lib\site-packages\pyreadline\console\__init__.py", line 14,in <module>
from console import *
File "C:\Python25\Lib\site-packages\pyreadline\console\console.py", line 118,in <module>
consolecodepage=sys.stdout.encoding
AttributeError: _SpoofOut instance has no attribute 'encoding'This is an easy fix with 2 lines of code to doctest.py right after doctest.py imports "sys", store the "sys.stdout.encoding" _sys_stdout_encoding = sys.stdout.encodingThen add this as an attribute "encoding" in the "_SpoofOut" class # Override some StringIO methods.
class _SpoofOut(StringIO): |
|
Does the attached, slightly simpler patch, also fix it? The revised patch doesn't seem to break anything on MacOS; I don't have access to Windows to test whether it still fixes the bug. |
|
Updated version: use sys.__stdout__ instead of sys.stdout, which might have already been replaced by another object lacking .encoding. |
|
The supported version and the trunk of pyreadline launchpad.net/pyreadline no long relies on sys.stdout for the encoding for the Windows console. Getting .encoding from sys.__stdout__ seems reasonable. If taken from sys.stdout at very last moment, only referencing sys.__stdout__ if sys.stdout is missing .encoding might be optimal, but since the bug was in pyreadline, and it is no longer trying to get .encoding from sys.stdout (which it shouldn't do anyway, because no guarantee is made that sys.stdout even has an attr .encoding), the whole point may be moot. I rely on your judgement. Since I only use the supported version of pyreadline, the error no longer happens in the unpatched code. |
|
While it could be argued that this is a bugfix, I think changing test modules in bugfix releases should be avoided. I would think that the simplest patch would be + encoding = sys.__stdout__.encoding in _Spoofout |
|
http://mail.scipy.org/pipermail/ipython-user/2007-April/004299.html talks about a patch to work around this problem. I think this is what the originator is talking about in msg99887 as in "Since I only use the supported version of pyreadline, the error no longer happens in the unpatched code.". So would we be justified in closing this as "won't fix" or should we patch doctest in any case? |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: