jorgenschaefer / elpy

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

Error Message 'in <string>' requires string as left operand, not int #782

Closed 0--key closed 8 years ago

0--key commented 8 years ago

Configuration

Virtualenv........: (/usr/local/share/DVCS/lib/Python/venv/) RPC Python........: 3.4.3 (/usr/local/share/DVCS/lib/Python/venv/bin/python) Interactive Python: python (/usr/local/share/DVCS/lib/Python/venv/bin/python) Emacs.............: 24.3.1 Elpy..............: 1.10.0 Jedi..............: 0.9.0 Rope..............: 0.10.3 Importmagic.......: 0.1.3 Autopep8..........: 0.1.3 Syntax checker....: flake8 (/usr/local/share/DVCS/lib/Python/venv/bin/flake8)

Traceback

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

Rope Debug Information


Reproduction:

```Python

source = '''
#!/usr/bin/env python
# -*- coding: utf-8 -*-

class Data(object):
    """ Data Store Class """

    products = {
        'milk': {'price': 1.50, 'quantity': 10},
        'eggs': {'price': 0.20, 'quantity': 100},
        'cheese': {'price': 2.00, 'quantity': 10}
    }

    def __get__(self, obj, klas):
        print("(Fetching from Data Store)")
        return {'products': self.products}

class BusinessLogic(object):
    """ Business logic holding data store instances """

    def __init__(self, data):
        self.data = data

    def product_list(self):
        return self.data['products'].keys()

    def product_information(self, product):
        return self.data['products'].get(product, None)

class Ui(object):
    """ UI interaction class """

    def __init__(self, logic):
        self.business_logic = logic

    def get_product_list(self):
        print('PRODUCT LIST:')
        for product in self.business_logic.product_list():
            print(product)
        print('')

    def get_product_information(self, product):
        product_info = self.business_logic.product_information(product)
        if product_info:
            print('PRODUCT INFORMATION:')
            print('Name: {0}, Price: {1:.2f}, Quantity: {2:}'.format(
                product.title(), product_info.get('price', 0),
                product_info.get('quantity', 0)))
        else:
            print('That product "{0}" does not exist in the records'.format(
                product))

def main():
    data = Data()
    logic = BusinessLogic(data)
    ui = Ui(logic)
    ui.get_product_list()
    ui.get_product_information('cheese')
    ui.get_product_information('eggs')
    ui.get_product_information('milk')
    ui.get_product_information('arepas')

if __name__ == '__main__':
    main()

### OUTPUT ###
# PRODUCT LIST:
# (Fetching from Data Store)
# cheese
# eggs
# milk
#
# (Fetching from Data Store)
# PRODUCT INFORMATION:
# Name: Cheese, Price: 2.00, Quantity: 10
# (Fetching from Data Store)
# PRODUCT INFORMATION:
# Name: Eggs, Price: 0.20, Quantity: 100
# (Fetching from Data Store)
# PRODUCT INFORMATION:    def __get__(self, obj, klas):
        print("(Fetching from Data Store)")
        return {'products': self.products}

class BusinessLogic(object):
    """ Business logic holding data store instances """

    def __init__(self, data):
        self.data = data

    def product_list(self):
        return self.data['products'].keys()

    def product_information(self, product):
        return self.data['products'].get(product, None)

class Ui(object):
    """ UI interaction class """

    def __init__(self, logic):
        self.business_logic = logic

    def get_product_list(self):
        print('PRODUCT LIST:')
        for product in self.business_logic.product_list():
            print(product)
        print('')

    def get_product_information(self, product):
        product_info = self.business_logic.product_information(product)
        if product_info:
            print('PRODUCT INFORMATION:')
            print('Name: {0}, Price: {1:.2f}, Quantity: {2:}'.format(
                product.title(), product_info.get('price', 0),
                product_info.get('quantity', 0)))
        else:
            print('That product "{0}" does not exist in the records'.format(
                product))

def main():
    data = Data()
    logic = BusinessLogic(data)
    ui = Ui(logic)
    ui.get_product_list()
    ui.get_product_information('cheese')
    ui.get_product_information('eggs')
    ui.get_product_information('milk')
    ui.get_product_information('arepas')

if __name__ == '__main__':
    main()

### OUTPUT ###
# PRODUCT LIST:
# (Fetching from Data Store)
# cheese
# eggs
# milk
#
# (Fetching from Data Store)
# PRODUCT INFORMATION:
# Name: Cheese, Price: 2.00, Quantity: 10
# (Fetching from Data Store)
# PRODUCT INFORMATION:
# Name: Eggs, Price: 0.20, Quantity: 100
# (Fetching from Data Store)
# PRODUCT INFORMATION:
# Name: Milk, Price: 1.50, Quantity: 10
# (Fetching from Data Store)
# That product "arepas" does not exist in the records
'''

project = rope.base.project.Project(
    "/usr/local/share/DVCS/lib/Python/edu/",
    ropefolder=None
)
resource = rope.base.libutils.path_to_resource(
    project,
    "/usr/local/share/DVCS/lib/Python/edu/python-patterns/3-tier.py",
    'file'
)
rope.contrib.codeassist.get_calltip(
    project, source, 831, resource, maxfixes=5, remove_self=True
)
jorgenschaefer commented 8 years ago

Hello, and thank you for the report! This is a bug in Rope. Sadly, the current maintainers of Rope are pretty explicit in that they do not care about fixing these types of bugs, so there is very little Elpy can do. The next release of Elpy will ignore all errors thrown by Rope, which should fix this problem, too.

0--key commented 8 years ago

Hello. Thanks a lot.

emacsway commented 8 years ago

As I see, there is used rope in Python3. Rope does not support python3 currently, just use rope_py3k

0--key commented 8 years ago

Yes it is venv with Python3 inside. Thank you for wise suggestion.