jorgenschaefer / elpy

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

Elpy crashed when typing apostrophe after open paren #1133

Open wvxvw opened 7 years ago

wvxvw commented 7 years ago
Error Message

There's an issue (138 != 137) with the diff parser. Please report:
--- 
+++ 
@@ -105,9 +105,6 @@
         strategy.apply_to_campaign(campaign)
         self.assert_action(

-    @attr('smoke')        # Load playbook.csv and confirm the action in playbok row for
-        # tier1 is KEEP
-
     @attr('smoke')
     def test_action_to_ron(self):
         # This strategy operates on RON campaigns Create a CSV that
@@ -137,5 +134,4 @@
         ron_model = CampaignModel.objects.get(name='Ron')
         campaign = MockCampaign(ron_model)
         strategy.apply_to_campaign(campaign)
-
-    +

Configuration

Virtualenv........: None
RPC Python........: 2.7.12 (/usr/bin/python)
Interactive Python: python (/usr/bin/python)
Emacs.............: 24.5.1
Elpy..............: 1.8.0
Jedi..............: 0.10.2
Rope..............: Not found (0.10.5 available)
Importmagic.......: 0.1.7
Syntax checker....: flake8 (/usr/local/bin/flake8)

Traceback

Traceback (most recent call last):
  File "/home/wvxvw/.emacs.d/elpa/elpy-1.8.0/elpy/jedibackend.py", line 303, in run_with_debug
    return getattr(script, name)()
  File "/usr/local/lib/python2.7/dist-packages/jedi/api/__init__.py", line 305, in call_signatures
    helpers.get_call_signature_details(self._get_module_node(), self._pos)
  File "/usr/local/lib/python2.7/dist-packages/jedi/cache.py", line 121, in wrapper
    result = method(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/jedi/api/__init__.py", line 140, in _get_module_node
    diff_cache=True,
  File "/usr/local/lib/python2.7/dist-packages/jedi/parser/python/__init__.py", line 104, in parse
    new_lines=lines
  File "/usr/local/lib/python2.7/dist-packages/jedi/parser/python/diff.py", line 174, in update
    % (last_pos, line_length, ''.join(diff))
Exception: There's an issue (138 != 137) with the diff parser. Please report:
--- 
+++ 
@@ -105,9 +105,6 @@
         strategy.apply_to_campaign(campaign)
         self.assert_action(

-    @attr('smoke')        # Load playbook.csv and confirm the action in playbok row for
-        # tier1 is KEEP
-
     @attr('smoke')
     def test_action_to_ron(self):
         # This strategy operates on RON campaigns Create a CSV that
@@ -137,5 +134,4 @@
         ron_model = CampaignModel.objects.get(name='Ron')
         campaign = MockCampaign(ron_model)
         strategy.apply_to_campaign(campaign)
-
-    +

Jedi Debug Information

[?] dbg: diff: line_lengths old: 137, new: 137
[?] dbg: diff 'equal' old[1:105] new[1:105]
[?] dbg: diff actually copy 1 to 105
[?] dbg: diff 'replace' old[106:106] new[106:106]
[?] dbg: parse part 106 to 108 (to 108 in parser)
[?] dbg: diff 'equal' old[107:137] new[107:137]
[?] dbg: diff actually copy 108 to 137
[?] warning: parser issue:
u"from __future__ import absolute_import\n\nimport csv\nimport os\nimport pandas\nimport uuid\nfrom bunch import Bunch\nfrom datetime import datetime\nfrom django.test.testcases import TestCase\nfrom nose.plugins.attrib import attr\n\nfrom ...models.Campaign import Campaign as CampaignModel\nfrom ...models.TargetDomain import TargetDomain as TargetDomainModel\nfrom ..PriceTierStrategy import PriceTierStrategy\nfrom .MockCampaign import MockCampaign\n\n\nclass TestPriceTierStrategy(TestCase):\n    def setUp(self):\n        self._original_getintent_api_mock = os.environ.get(\n            'GETINTENT_API_MOCK', '0')\n        os.environ['GETINTENT_API_MOCK'] = '1'\n        self.name = uuid.uuid4().hex\n        self.populate_tables()\n\n    def tearDown(self):\n        os.environ['GETINTENT_API_MOCK'] = self._original_getintent_api_mock\n\n    def populate_tables(self):\n        campaigns = [\n            CampaignModel(name='Ron',\n                          is_ron=True,\n                          supply_platform='',\n                          supply_platform_id='ron',\n                          demand_platform='',\n                          demand_platform_id='ron',\n                          env='',\n                          ssp='',\n                          status='active'),\n        ]\n\n        CampaignModel.objects.bulk_create(campaigns)\n        ron = CampaignModel.objects.get(name='Ron')\n        tier = CampaignModel(name='Keep Me',\n                             supply_platform='',\n                             supply_platform_id='tier',\n                             demand_platform='',\n                             demand_platform_id='tier',\n                             env='',\n                             ssp='',\n                             status='active',\n                             supply_bid=0.5,\n                             ron_campaign=ron)\n        tier.save()\n\n        timestamp = datetime(2017, 5, 16)\n        domain = TargetDomainModel(\n            campaign=tier,\n            domain='cnn.com',\n            created=timestamp,\n            modified=timestamp)\n        domain.save()\n        domain.created = timestamp\n        domain.save()\n\n    def assert_action(self, tier, action):\n        with open('playbook.csv', 'r') as f:\n            reader = csv.DictReader(f)\n            found = False\n            for record in reader:\n                if record['tier_name'] == tier:\n                    found = True\n                    assert record['action'] == action, \\\n                        'Must keep this record'\n            assert found, 'Must find at least one record to keep'\n\n    @attr('smoke')\n    def test_action_keep(self):\n        # This strategy operates on RON campaigns Create a CSV that\n        # will lead to a decision to KEEP a campaign in its current\n        # tier Create RON campaign instance similar to run() in\n        # HourlyPricingScenario Call apply_to_campaign() Use dry-run\n        # when creating the context for this scenario/strategy The\n        # strategy creates a local file playbook.csv - read it and\n        # verify results\n\n        day = datetime(2017, 5, 17)\n        # 11/05/2017 46240 01-edito-atf-laplacemedia-1.fr 27 0.04 35\n        # 0.3533233 0.012366316\n        keep_rows = [{\n            'date_': day,\n            'supply_campaign_id': 'tier',\n            'domain': 'cnn.com',\n            'demand_impressions': 0,\n            'revenue': 715.0,\n            'supply_impressions': 1000,\n            'supply_cpm': 0.5,\n            'cost': 0.5\n        }]\n        report = pandas.DataFrame(keep_rows)\n        strategy = PriceTierStrategy(\n            context=Bunch(dry_run=True, domain_report=report, day=day))\n        ron_model = CampaignModel.objects.get(name='Ron')\n        campaign = MockCampaign(ron_model)\n        strategy.apply_to_campaign(campaign)\n        self.assert_a\n\n    @attr('smoke')\n    def test_action_to_ron(self):\n        # This strategy operates on RON campaigns Create a CSV that\n        # will lead to a decision to KEEP a campaign in its current\n        # tier Create RON campaign instance similar to run() in\n        # HourlyPricingScenario Call apply_to_campaign() Use dry-run\n        # when creating the context for this scenario/strategy The\n        # strategy creates a local file playbook.csv - read it and\n        # verify results\n\n        day = datetime(2017, 5, 17)\n        # 11/05/2017 46240 01-edito-atf-laplacemedia-1.fr 27 0.04 35\n        # 0.3533233 0.012366316\n        to_ron_rows = [{\n            'date_': day,\n            'supply_campaign_id': 'tier',\n            'domain': 'cnn.com',\n            'demand_impressions': 0,\n            'revenue': 715.0,\n            'supply_impressions': 1000,\n            'supply_cpm': 0.5,\n            'cost': 0.5\n        }]\n        report = pandas.DataFrame(to_ron_rows)\n        strategy = PriceTierStrategy(\n            context=Bunch(dry_run=True, domain_report=report, day=day))\n        ron_model = CampaignModel.objects.get(name='Ron')\n        campaign = MockCampaign(ron_model)\n        strategy.apply_to_campaign(campaign)\n"
u"from __future__ import absolute_import\n\nimport csv\nimport os\nimport pandas\nimport uuid\nfrom bunch import Bunch\nfrom datetime import datetime\nfrom django.test.testcases import TestCase\nfrom nose.plugins.attrib import attr\n\nfrom ...models.Campaign import Campaign as CampaignModel\nfrom ...models.TargetDomain import TargetDomain as TargetDomainModel\nfrom ..PriceTierStrategy import PriceTierStrategy\nfrom .MockCampaign import MockCampaign\n\n\nclass TestPriceTierStrategy(TestCase):\n    def setUp(self):\n        self._original_getintent_api_mock = os.environ.get(\n            'GETINTENT_API_MOCK', '0')\n        os.environ['GETINTENT_API_MOCK'] = '1'\n        self.name = uuid.uuid4().hex\n        self.populate_tables()\n\n    def tearDown(self):\n        os.environ['GETINTENT_API_MOCK'] = self._original_getintent_api_mock\n\n    def populate_tables(self):\n        campaigns = [\n            CampaignModel(name='Ron',\n                          is_ron=True,\n                          supply_platform='',\n                          supply_platform_id='ron',\n                          demand_platform='',\n                          demand_platform_id='ron',\n                          env='',\n                          ssp='',\n                          status='active'),\n        ]\n\n        CampaignModel.objects.bulk_create(campaigns)\n        ron = CampaignModel.objects.get(name='Ron')\n        tier = CampaignModel(name='Keep Me',\n                             supply_platform='',\n                             supply_platform_id='tier',\n                             demand_platform='',\n                             demand_platform_id='tier',\n                             env='',\n                             ssp='',\n                             status='active',\n                             supply_bid=0.5,\n                             ron_campaign=ron)\n        tier.save()\n\n        timestamp = datetime(2017, 5, 16)\n        domain = TargetDomainModel(\n            campaign=tier,\n            domain='cnn.com',\n            created=timestamp,\n            modified=timestamp)\n        domain.save()\n        domain.created = timestamp\n        domain.save()\n\n    def assert_action(self, tier, action):\n        with open('playbook.csv', 'r') as f:\n            reader = csv.DictReader(f)\n            found = False\n            for record in reader:\n                if record['tier_name'] == tier:\n                    found = True\n                    assert record['action'] == action, \\\n                        'Must keep this record'\n            assert found, 'Must find at least one record to keep'\n\n    @attr('smoke')\n    def test_action_keep(self):\n        # This strategy operates on RON campaigns Create a CSV that\n        # will lead to a decision to KEEP a campaign in its current\n        # tier Create RON campaign instance similar to run() in\n        # HourlyPricingScenario Call apply_to_campaign() Use dry-run\n        # when creating the context for this scenario/strategy The\n        # strategy creates a local file playbook.csv - read it and\n        # verify results\n\n        day = datetime(2017, 5, 17)\n        # 11/05/2017 46240 01-edito-atf-laplacemedia-1.fr 27 0.04 35\n        # 0.3533233 0.012366316\n        keep_rows = [{\n            'date_': day,\n            'supply_campaign_id': 'tier',\n            'domain': 'cnn.com',\n            'demand_impressions': 0,\n            'revenue': 715.0,\n            'supply_impressions': 1000,\n            'supply_cpm': 0.5,\n            'cost': 0.5\n        }]\n        report = pandas.DataFrame(keep_rows)\n        strategy = PriceTierStrategy(\n            context=Bunch(dry_run=True, domain_report=report, day=day))\n        ron_model = CampaignModel.objects.get(name='Ron')\n        campaign = MockCampaign(ron_model)\n        strategy.apply_to_campaign(campaign)\n        self.assert_action(\n\n    @attr('smoke')\n    def test_action_to_ron(self):\n        # This strategy operates on RON campaigns Create a CSV that\n        # will lead to a decision to KEEP a campaign in its current\n        # tier Create RON campaign instance similar to run() in\n        # HourlyPricingScenario Call apply_to_campaign() Use dry-run\n        # when creating the context for this scenario/strategy The\n        # strategy creates a local file playbook.csv - read it and\n        # verify results\n\n        day = datetime(2017, 5, 17)\n        # 11/05/2017 46240 01-edito-atf-laplacemedia-1.fr 27 0.04 35\n        # 0.3533233 0.012366316\n        to_ron_rows = [{\n            'date_': day,\n            'supply_campaign_id': 'tier',\n            'domain': 'cnn.com',\n            'demand_impressions': 0,\n            'revenue': 715.0,\n            'supply_impressions': 1000,\n            'supply_cpm': 0.5,\n            'cost': 0.5\n        }]\n        report = pandas.DataFrame(to_ron_rows)\n        strategy = PriceTierStrategy(\n            context=Bunch(dry_run=True, domain_report=report, day=day))\n        ron_model = CampaignModel.objects.get(name='Ron')\n        campaign = MockCampaign(ron_model)\n        strategy.apply_to_campaign(campaign)\n"

Reproduction:

import jedi

source = '''\
from __future__ import absolute_import

import csv
import os
import pandas
import uuid
from bunch import Bunch
from datetime import datetime
from django.test.testcases import TestCase
from nose.plugins.attrib import attr

from ...models.Campaign import Campaign as CampaignModel
from ...models.TargetDomain import TargetDomain as TargetDomainModel
from ..PriceTierStrategy import PriceTierStrategy
from .MockCampaign import MockCampaign

class TestPriceTierStrategy(TestCase):
    def setUp(self):
        self._original_getintent_api_mock = os.environ.get(
            'GETINTENT_API_MOCK', '0')
        os.environ['GETINTENT_API_MOCK'] = '1'
        self.name = uuid.uuid4().hex
        self.populate_tables()

    def tearDown(self):
        os.environ['GETINTENT_API_MOCK'] = self._original_getintent_api_mock

    def populate_tables(self):
        campaigns = [
            CampaignModel(name='Ron',
                          is_ron=True,
                          supply_platform='',
                          supply_platform_id='ron',
                          demand_platform='',
                          demand_platform_id='ron',
                          env='',
                          ssp='',
                          status='active'),
        ]

        CampaignModel.objects.bulk_create(campaigns)
        ron = CampaignModel.objects.get(name='Ron')
        tier = CampaignModel(name='Keep Me',
                             supply_platform='',
                             supply_platform_id='tier',
                             demand_platform='',
                             demand_platform_id='tier',
                             env='',
                             ssp='',
                             status='active',
                             supply_bid=0.5,
                             ron_campaign=ron)
        tier.save()

        timestamp = datetime(2017, 5, 16)
        domain = TargetDomainModel(
            campaign=tier,
            domain='cnn.com',
            created=timestamp,
            modified=timestamp)
        domain.save()
        domain.created = timestamp
        domain.save()

    def assert_action(self, tier, action):
        with open('playbook.csv', 'r') as f:
            reader = csv.DictReader(f)
            found = False
            for record in reader:
                if record['tier_name'] == tier:
                    found = True
                    assert record['action'] == action, \
                        'Must keep this record'
            assert found, 'Must find at least one record to keep'

    @attr('smoke')
    def test_action_keep(self):
        # This strategy operates on RON campaigns Create a CSV that
        # will lead to a decision to KEEP a campaign in its current
        # tier Create RON campaign instance similar to run() in
        # HourlyPricingScenario Call apply_to_campaign() Use dry-run
        # when creating the context for this scenario/strategy The
        # strategy creates a local file playbook.csv - read it and
        # verify results

        day = datetime(2017, 5, 17)
        # 11/05/2017 46240 01-edito-atf-laplacemedia-1.fr 27 0.04 35
        # 0.3533233 0.012366316
        keep_rows = [{
            'date_': day,
            'supply_campaign_id': 'tier',
            'domain': 'cnn.com',
            'demand_impressions': 0,
            'revenue': 715.0,
            'supply_impressions': 1000,
            'supply_cpm': 0.5,
            'cost': 0.5
        }]
        report = pandas.DataFrame(keep_rows)
        strategy = PriceTierStrategy(
            context=Bunch(dry_run=True, domain_report=report, day=day))
        ron_model = CampaignModel.objects.get(name='Ron')
        campaign = MockCampaign(ron_model)
        strategy.apply_to_campaign(campaign)
        self.assert_action(

    @attr('smoke')
    def test_action_to_ron(self):
        # This strategy operates on RON campaigns Create a CSV that
        # will lead to a decision to KEEP a campaign in its current
        # tier Create RON campaign instance similar to run() in
        # HourlyPricingScenario Call apply_to_campaign() Use dry-run
        # when creating the context for this scenario/strategy The
        # strategy creates a local file playbook.csv - read it and
        # verify results

        day = datetime(2017, 5, 17)
        # 11/05/2017 46240 01-edito-atf-laplacemedia-1.fr 27 0.04 35
        # 0.3533233 0.012366316
        to_ron_rows = [{
            'date_': day,
            'supply_campaign_id': 'tier',
            'domain': 'cnn.com',
            'demand_impressions': 0,
            'revenue': 715.0,
            'supply_impressions': 1000,
            'supply_cpm': 0.5,
            'cost': 0.5
        }]
        report = pandas.DataFrame(to_ron_rows)
        strategy = PriceTierStrategy(
            context=Bunch(dry_run=True, domain_report=report, day=day))
        ron_model = CampaignModel.objects.get(name='Ron')
        campaign = MockCampaign(ron_model)
        strategy.apply_to_campaign(campaign)
'''

script = jedi.Script(column=27, source=source, line=106, encoding='utf-8', path=u'/home/wvxvw/projects/JaneDoe/web/ron/tiers/test/TestPriceTierStrategy.py')
script.call_signatures()
jorgenschaefer commented 7 years ago

Thank you for the report! This is a bug in Jedi, apparently. I'd report it upstream, but the usual response is to wait for the next release – if you like, you can try the development version of Jedi. Does this happen regularly and stops you from working, or was that just a one-off thing?

wvxvw commented 7 years ago

It's not very common, but it doesn't happen in just this scenario. It happens whenever it parses a function call's opening parenthesis followed by non-alphanumeric symbol. Once I have more free time, I'll try to use a different Jedi version and report back if I see any improvements.