Skip to content

Commit

Permalink
unicode issues with docstrings should be gone, fixes #420
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhalter committed Jul 18, 2014
1 parent e07f513 commit 2616143
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 7 additions & 1 deletion jedi/parser/representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ def raw_doc(self):
""" Returns a cleaned version of the docstring token. """
try:
# Returns a literal cleaned version of the ``Token``.
return unicode(cleandoc(literal_eval(self._doc_token.string)))
cleaned = cleandoc(literal_eval(self._doc_token.string))
# Since we want the docstr output to be always unicode, just force
# it.
if is_py3 or isinstance(cleaned, unicode):
return cleaned
else:
return unicode(cleaned, 'UTF-8', 'replace')
except AttributeError:
return u('')

Expand Down
10 changes: 8 additions & 2 deletions test/test_parser/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from jedi._compatibility import u
# -*- coding: utf-8 -*-

from jedi._compatibility import u, is_py3
from jedi.parser import Parser
from jedi.parser.user_context import UserContextParser
from jedi.parser import representation as pr
Expand Down Expand Up @@ -136,4 +138,8 @@ def foo(object):
return 1
'''

assert Parser(dedent(u(source))).module.subscopes[0].raw_doc == '\xff'
doc = Parser(dedent(u(source))).module.subscopes[0].raw_doc
if is_py3:
assert doc == '\xff'
else:
assert doc == u('�')

0 comments on commit 2616143

Please sign in to comment.