jorgenschaefer / elpy

Emacs Python Development Environment
GNU General Public License v3.0
1.9k stars 262 forks source link

# -*- coding: utf-8 -*- error #785

Closed scloudyy closed 8 years ago

scloudyy commented 8 years ago

When type # -- coding: utf-8 -- on the top of buffer in each file error will occur, and cursor can hardly move. When type #!/usr/bin/env python3 will also make this error.

Error Message

'in <string>' requires string as left operand, not int

Configuration

Virtualenv........: None
RPC Python........: 3.5.0 (/home/sclouds/.pyenv/shims/python)
Interactive Python: ipython (/home/sclouds/.pyenv/shims/ipython)
Emacs.............: 24.5.3
Elpy..............: 1.10.0
Jedi..............: 0.9.0
Rope..............: 0.10.3
Importmagic.......: 0.1.3
Autopep8..........: 0.1.3
Syntax checker....: pyflakes (/home/sclouds/.pyenv/shims/pyflakes)

Traceback

Traceback (most recent call last):
  File "/home/sclouds/.emacs.d/elpa/elpy-20151101.401/elpy/ropebackend.py", line 100, in call_rope
    **kwargs)
  File "/home/sclouds/.pyenv/versions/3.5.0/lib/python3.5/site-packages/rope/contrib/codeassist.py", line 97, in get_calltip
    pyname = fixer.pyname_at(offset)
  File "/home/sclouds/.pyenv/versions/3.5.0/lib/python3.5/site-packages/rope/contrib/fixsyntax.py", line 51, in pyname_at
    pymodule = self.get_pymodule()
  File "/home/sclouds/.pyenv/versions/3.5.0/lib/python3.5/site-packages/rope/base/utils.py", line 11, in _wrapper
    setattr(self, name, func(self, *args, **kwds))
  File "/home/sclouds/.pyenv/versions/3.5.0/lib/python3.5/site-packages/rope/contrib/fixsyntax.py", line 27, in get_pymodule
    self.resource.read() == code:
  File "/home/sclouds/.pyenv/versions/3.5.0/lib/python3.5/site-packages/rope/base/resources.py", line 111, in read
    return fscommands.file_data_to_unicode(data)
  File "/home/sclouds/.pyenv/versions/3.5.0/lib/python3.5/site-packages/rope/base/fscommands.py", line 208, in file_data_to_unicode
    result = _decode_data(data, encoding)
  File "/home/sclouds/.pyenv/versions/3.5.0/lib/python3.5/site-packages/rope/base/fscommands.py", line 218, in _decode_data
    encoding = read_str_coding(data)
  File "/home/sclouds/.pyenv/versions/3.5.0/lib/python3.5/site-packages/rope/base/fscommands.py", line 260, in read_str_coding
    return _find_coding(source[:second])
  File "/home/sclouds/.pyenv/versions/3.5.0/lib/python3.5/site-packages/rope/base/fscommands.py", line 270, in _find_coding
    if text[start] not in '=:':
TypeError: 'in <string>' requires string as left operand, not int

Rope Debug Information

Reproduction:


source = '''
# -*- coding: utf-8 -*-

import sys

name = sys.argv
'''

project = rope.base.project.Project(
    "/home/sclouds/testpy/",
    ropefolder=None
)
resource = rope.base.libutils.path_to_resource(
    project,
    "/home/sclouds/testpy/test2.py",
    'file'
)
rope.contrib.codeassist.get_calltip(
    project, source, 16, resource, maxfixes=5, remove_self=True
)
ghost commented 8 years ago

Do you use rope_py3k?

jorgenschaefer commented 8 years ago

Hello, and thanks for the report! This is a bug in Rope when using Python 3. You will have to use the rope_py3k package instead of the rope package if you use Rope with Python 3. Does this help?

scloudyy commented 8 years ago

Thanks for your quick reply . So how can I change rope to rope_py3k? just

pip uninstall rope
pip install rope_py3k

?

jorgenschaefer commented 8 years ago

That should work, yes. Also restart Elpy (M-x elpy-rpc-restart)

jorgenschaefer commented 8 years ago

Lacking further updates, I assume this problem is solved. Please do not hesitate to open a new issue if you have any further problems.