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

UnicodeEncodeError on pydoc's CLI #50874

Closed
christoph mannequin opened this issue Aug 2, 2009 · 10 comments
Closed

UnicodeEncodeError on pydoc's CLI #50874

christoph mannequin opened this issue Aug 2, 2009 · 10 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@christoph
Copy link
Mannequin

christoph mannequin commented Aug 2, 2009

BPO 6625
Nosy @vstinner, @merwok, @akitada, @florentx, @Bluehorn, @berkerpeksag
Files
  • unicode.patch: Patch encoding output with system encoding
  • pydoc_unicode_testcase_notworking.diff: Added test for unicode (defunc)
  • issue6625_pydoc.diff: Patch, apply to trunk
  • 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 = <Date 2014-01-13.08:40:41.805>
    created_at = <Date 2009-08-02.13:00:46.380>
    labels = ['type-bug', 'library']
    title = "UnicodeEncodeError on pydoc's CLI"
    updated_at = <Date 2014-01-13.10:56:30.737>
    user = 'https://bugs.python.org/christoph'

    bugs.python.org fields:

    activity = <Date 2014-01-13.10:56:30.737>
    actor = 'torsten'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-01-13.08:40:41.805>
    closer = 'berker.peksag'
    components = ['Library (Lib)']
    creation = <Date 2009-08-02.13:00:46.380>
    creator = 'christoph'
    dependencies = []
    files = ['14626', '14656', '16296']
    hgrepos = []
    issue_num = 6625
    keywords = ['patch']
    message_count = 10.0
    messages = ['91182', '91295', '91315', '99716', '99717', '99723', '99728', '208006', '208013', '208018']
    nosy_count = 8.0
    nosy_names = ['ggenellina', 'vstinner', 'christoph', 'eric.araujo', 'akitada', 'flox', 'torsten', 'berker.peksag']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue6625'
    versions = ['Python 2.7']

    @christoph
    Copy link
    Mannequin Author

    christoph mannequin commented Aug 2, 2009

    pydoc fails with a UnicodeEncodeError for properly specified Unicode
    docstrings (u"""...""") on the command line interface.

    See attached patch that encodes the output with the system's encoding.

    @christoph christoph mannequin added the extension-modules C modules in the Modules dir label Aug 2, 2009
    @ggenellina
    Copy link
    Mannequin

    ggenellina mannequin commented Aug 5, 2009

    After applying your patch, are string (not unicode) docstrings still
    being handled properly?
    Adding a test case (in Lib/test/test_pydoc.py) would be nice too.

    @christoph
    Copy link
    Mannequin Author

    christoph mannequin commented Aug 5, 2009

    Here is a diff for test/test_pydoc.py (against Python2.6) which though
    doesn't trigger due to how Python handles output encoding. This test
    here will pass, but pydoc will still fail:

    $ pydoc test/pydoc_mod.py > /dev/null
    Traceback (most recent call last):
      File "/usr/bin/pydoc", line 5, in <module>
        pydoc.cli()
      File "/usr/lib/python2.5/pydoc.py", line 2226, in cli
        help.help(arg)
      File "/usr/lib/python2.5/pydoc.py", line 1691, in help
        else: doc(request, 'Help on %s:')
      File "/usr/lib/python2.5/pydoc.py", line 1482, in doc
        pager(title % desc + '\n\n' + text.document(object, name))
      File "/usr/lib/python2.5/pydoc.py", line 1300, in pager
        pager(text)
      File "/usr/lib/python2.5/pydoc.py", line 1398, in plainpager
        sys.stdout.write(plain(text))
    UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in
    position 936: ordinal not in range(128)

    @Bluehorn
    Copy link
    Mannequin

    Bluehorn mannequin commented Feb 22, 2010

    This problem persists with current Python 2.7 trunk (I used hg mirror):
    52aa81c14f87 (trunk) tip

    I also checked with the py3k branch and it does not show this limitation. Just as one would have expected...

    @Bluehorn
    Copy link
    Mannequin

    Bluehorn mannequin commented Feb 22, 2010

    As Subversion is still the master repo (correct me if I am wrong), the hg version tested maps to r78290 in subversion on /trunk.

    @florentx
    Copy link
    Mannequin

    florentx mannequin commented Feb 22, 2010

    This patch do not work for me.

    See the patch attached on duplicate bug bpo-7625, with more tests:
    http://bugs.python.org/file15831/issue7675_pydoc_v2.diff

    @florentx florentx mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error and removed extension-modules C modules in the Modules dir labels Feb 22, 2010
    @florentx
    Copy link
    Mannequin

    florentx mannequin commented Feb 22, 2010

    Patch with same tests as the previous one, but using better heuristic for output encoding (like Christoph patch).
    Added the "replace" error handling, if the output encoding cannot encode all characters.

    @akitada
    Copy link
    Mannequin

    akitada mannequin commented Jan 13, 2014

    I suppose this is a duplicate of bpo-1065986.

    @berkerpeksag
    Copy link
    Member

    I suppose this is a duplicate of bpo-1065986.

    Yes, it is. I created a test file from the tests in issue6625_pydoc.diff and ran it on the current 2.7 branch.

    def foo():
        u"""fooo bar
        baz
        \xfcnicode\u2026"""
        return 42
    
    def bar():
        u"f\xfcr Elise"
        return 11

    @Bluehorn
    Copy link
    Mannequin

    Bluehorn mannequin commented Jan 13, 2014

    I tested this as well and it seems to work now. :-) Thanks for fixing it!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant