rohdef / pysmell

PySmell is an attempt to create an IDE completion helper for python.
http://code.google.com/p/pysmell/
7 stars 2 forks source link

Error why handling unicode chars #12

Open rohdef opened 13 years ago

rohdef commented 13 years ago

What steps will reproduce the problem?

  1. Create python class using utf-8
  2. From another file create object of recently created class
  3. Try to complete its methods

What is the expected output? What do you see instead? Expected: method's list Instead we got a nice traceback, something like attached.

What version of the product are you using? On what operating system? PySmell 0.7.1 on Gentoo Python 2.5

Please provide any additional information below. Solution to this problem was replacing str() with unicode() in codefinder.py at lines: 301, 314, 316 (I don't know why, but I had to change[remove '.value'] also lines 337 and 340 in codefinder.py, because of "object has no attribute 'value'". Is this another issue?)

rohdef commented 13 years ago

i have this problem, too. when I use emacs. M-x pysmell-make-tags RET this step is OK. then M-/ can't work, appear this problem.

debian lenny, python 2.5, Pymacs 0.24 beta1, pysmell 0.7.3

rohdef commented 13 years ago

if the .py file has multi-byte character , pysmell doesn't work!

just like this :

pymacs-report-error: Python: Traceback (most recent call last): File "/usr/lib/python2.5/site-packages/Pymacs/pymacs.py", line 147, in loop value = eval(text) File "", line 1, in File "/usr/lib/python2.5/site-packages/pysmell/emacshelper.py", line 24, in get_completions options = idehelper.detectCompletionType(fullPath, origSource, lineNo, origCol, base, PYSMELLDICT) File "/usr/lib/python2.5/site-packages/pysmell/idehelper.py", line 216, in detectCompletionType AST = getSafeTree(origSource, lineNo) File "/usr/lib/python2.5/site-packages/pysmell/codefinder.py", line 487, in getSafeTree tree = compiler.parse(replacedSource) File "/usr/lib/python2.5/compiler/transformer.py", line 52, in parse return Transformer().parsesuite(buf) File "/usr/lib/python2.5/compiler/transformer.py", line 129, in parsesuite return self.transform(parser.suite(text)) UnicodeEncodeError: 'ascii' codec can't encode characters in position 103-107: ordinal not in range(128)

rohdef commented 13 years ago

change codefinder.py ,lines 487 to : tree = compiler.parse(replacedSource.encode('ascii', 'ignore'))

rohdef commented 13 years ago

Traceback (most recent call last): File "/usr/lib/python2.5/site-packages/pysmell-0.7.1-py2.5.egg/pysmell/idehelper.py", line 262, in detectCompletionType klass, parents = inferInstance(fullPath, AST, lineNo, var, PYSMELLDICT) File "/usr/lib/python2.5/site-packages/pysmell-0.7.1-py2.5.egg/pysmell/idehelper.py", line 105, in inferInstance names, klasses = getNames(AST) File "/usr/lib/python2.5/site-packages/pysmell-0.7.1-py2.5.egg/pysmell/codefinder.py", line 527, in getNames compiler.walk(tree, inferer, walker=ExampleASTVisitor(), verbose=1) File "/usr/lib/python2.5/compiler/visitor.py", line 106, in walk walker.preorder(tree, visitor) File "/usr/lib/python2.5/compiler/visitor.py", line 63, in preorder self.dispatch(tree, args) # XXX args make sense? File "/usr/lib/python2.5/compiler/visitor.py", line 84, in dispatch meth(node, *args) File "/usr/lib/python2.5/site-packages/pysmell-0.7.1-py2.5.egg/pysmell/codefinder.py", line 505, in handleChildren BaseVisitor.handleChildren(self, node)

......

File "/usr/lib/python2.5/site-packages/pysmell-0.7.1-py2.5.egg/pysmell/codefinder.py", line 129, in handleChildren self.visit(c) File "/usr/lib/python2.5/compiler/visitor.py", line 84, in dispatch meth(node, _args) File "/usr/lib/python2.5/site-packages/pysmell-0.7.1-py2.5.egg/pysmell/codefinder.py", line 102, in decorated self.handleChildren(args[0]) meth(node, args) File "/usr/lib/python2.5/site-packages/pysmell-0.7.1-py2.5.egg/pysmell/codefinder.py", line 101, in decorated fun(self, args, *_kwargs) File "/usr/lib/python2.5/site-packages/pysmell-0.7.1-py2.5.egg/pysmell/codefinder.py", line 516, in visitAssign self.names[name] = getName(node.expr) File "/usr/lib/python2.5/site-packages/pysmell-0.7.1-py2.5.egg/pysmell/codefinder.py", line 316, in getName return repr(str(node.value)) UnicodeEncodeError: 'ascii' codec can't encode characters in position 2-3: ordinal not in range(128)