X Tutup
The Wayback Machine - https://web.archive.org/web/20241214193540/https://github.com/python/cpython/issues/44902
Skip to content
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

Closed
manuelg mannequin opened this issue Apr 26, 2007 · 6 comments
Closed

doctest work with Windows PyReadline #44902

manuelg mannequin opened this issue Apr 26, 2007 · 6 comments
Labels
OS-windows stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@manuelg
Copy link
Mannequin

manuelg mannequin commented Apr 26, 2007

BPO 1708316
Nosy @terryjreedy
Files
  • doctest.py: doctest.py (added 2 lines: "encoding")
  • doctest-patch.txt: Second version
  • 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:

    assignee = None
    closed_at = None
    created_at = <Date 2007-04-26.19:02:04.000>
    labels = ['type-feature', 'library', 'OS-windows']
    title = 'doctest work with Windows PyReadline'
    updated_at = <Date 2019-04-26.17:24:05.738>
    user = 'https://bugs.python.org/manuelg'

    bugs.python.org fields:

    activity = <Date 2019-04-26.17:24:05.738>
    actor = 'BreamoreBoy'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)', 'Windows']
    creation = <Date 2007-04-26.19:02:04.000>
    creator = 'manuelg_'
    dependencies = []
    files = ['2362', '16320']
    hgrepos = []
    issue_num = 1708316
    keywords = ['patch']
    message_count = 6.0
    messages = ['31900', '99822', '99829', '99887', '112754', '222707']
    nosy_count = 2.0
    nosy_names = ['terry.reedy', 'manuelg_']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue1708316'
    versions = ['Python 3.2']

    @manuelg
    Copy link
    Mannequin Author

    manuelg mannequin commented Apr 26, 2007

    doctest crashes when working with Windows PyReadline (PyReadline is a component of Windows IPython)

    PyReadline expects "_SpoofOut" to have an "encoding" attribute

    E
    ======================================================================
    ERROR: testDocTest (main.TestDocTest)
    ----------------------------------------------------------------------

    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.encoding

    Then add this as an attribute "encoding" in the "_SpoofOut" class

    # Override some StringIO methods.
    class _SpoofOut(StringIO):
    ....
            
    encoding = _sys_stdout_encoding
    

    @manuelg manuelg mannequin added stdlib Python modules in the Lib dir labels Apr 26, 2007
    @akuchling
    Copy link
    Member

    Does the attached, slightly simpler patch, also fix it?
    The patch just sets the .encoding attribute after
    creating it with _SpoofOut().

    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.

    @akuchling
    Copy link
    Member

    Updated version: use sys.__stdout__ instead of sys.stdout, which might have already been replaced by another object lacking .encoding.

    @manuelg
    Copy link
    Mannequin Author

    manuelg mannequin commented Feb 23, 2010

    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.

    @terryjreedy
    Copy link
    Member

    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

    @terryjreedy terryjreedy added type-feature A feature request or enhancement labels Aug 4, 2010
    @florentx florentx mannequin added OS-windows labels Aug 10, 2010
    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jul 10, 2014

    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?

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @iritkatriel iritkatriel closed this as not planned Won't fix, can't repro, duplicate, stale Oct 4, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    OS-windows stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants
    X Tutup