jorgenschaefer / elpy

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

jedi: incomplete input: type='ENDMARKER', value='', start_pos=(37, 0) #944

Closed pmatos closed 6 years ago

pmatos commented 8 years ago

Elpy gave me this:

Error Message

incomplete input: type='ENDMARKER', value='', start_pos=(37, 0)

Configuration

Virtualenv........: None
RPC Python........: 3.4.3 (/usr/bin/python3)
Interactive Python: ipython3 (/usr/bin/ipython3)
Emacs.............: 24.5.1
Elpy..............: 1.10.0
Jedi..............: 0.9.0
Rope..............: Not found (0.10.3 available)
Importmagic.......: 0.1.7
Autopep8..........: 0.1.7
Syntax checker....: pycheckers (/home/pmatos/INSTALLS/bin/pycheckers)

Traceback

Traceback (most recent call last):
  File "/usr/lib/python3.4/site-packages/jedi/cache.py", line 141, in wrapper
    return getattr(self, name)
AttributeError: 'UserContextParser' object has no attribute '_user_stmt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/site-packages/jedi/cache.py", line 141, in wrapper
    return getattr(self, name)
AttributeError: 'UserContextParser' object has no attribute '__parser'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pmatos/.emacs.d/elpa/elpy-20151101.401/elpy/jedibackend.py", line 227, in run_with_debug
    return getattr(script, name)()
  File "/usr/lib/python3.4/site-packages/jedi/api/__init__.py", line 515, in call_signatures
    stmt = self._get_under_cursor_stmt(call_txt, start_pos)
  File "/usr/lib/python3.4/site-packages/jedi/evaluate/cache.py", line 41, in wrapper
    rv = function(obj, *args, **kwargs)
  File "/usr/lib/python3.4/site-packages/jedi/api/__init__.py", line 309, in _get_under_cursor_stmt
    user_stmt = self._parser.user_stmt()
  File "/usr/lib/python3.4/site-packages/jedi/cache.py", line 143, in wrapper
    result = func(self)
  File "/usr/lib/python3.4/site-packages/jedi/parser/user_context.py", line 293, in user_stmt
    module = self.module()
  File "/usr/lib/python3.4/site-packages/jedi/parser/user_context.py", line 339, in module
    return self._parser().module
  File "/usr/lib/python3.4/site-packages/jedi/cache.py", line 143, in wrapper
    result = func(self)
  File "/usr/lib/python3.4/site-packages/jedi/parser/user_context.py", line 283, in _parser
    parser = FastParser(self._grammar, self._source, self._path)
  File "/usr/lib/python3.4/site-packages/jedi/parser/fast.py", line 109, in __call__
    p.update(source)
  File "/usr/lib/python3.4/site-packages/jedi/parser/fast.py", line 257, in update
    self._parse(source)
  File "/usr/lib/python3.4/site-packages/jedi/parser/fast.py", line 383, in _parse
    line_offset, nodes)
  File "/usr/lib/python3.4/site-packages/jedi/parser/fast.py", line 435, in _get_node
    p = Parser(self._grammar, parser_code, self.module_path, tokenizer=tokenizer)
  File "/usr/lib/python3.4/site-packages/jedi/parser/__init__.py", line 155, in __init__
    self.module = p.parse(self._tokenize(tokenizer))
  File "/usr/lib/python3.4/site-packages/jedi/parser/pgen2/parse.py", line 114, in parse
    raise ParseError("incomplete input", type, value, start_pos)
jedi.parser.pgen2.parse.ParseError: incomplete input: type='ENDMARKER', value='', start_pos=(37, 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/site-packages/jedi/cache.py", line 141, in wrapper
    return getattr(self, name)
AttributeError: 'UserContextParser' object has no attribute '_user_stmt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/site-packages/jedi/cache.py", line 141, in wrapper
    return getattr(self, name)
AttributeError: 'UserContextParser' object has no attribute '__parser'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pmatos/.emacs.d/elpa/elpy-20151101.401/elpy/jedibackend.py", line 341, in run_with_debug
    return getattr(script, name)()
  File "/usr/lib/python3.4/site-packages/jedi/api/__init__.py", line 515, in call_signatures
    stmt = self._get_under_cursor_stmt(call_txt, start_pos)
  File "/usr/lib/python3.4/site-packages/jedi/evaluate/cache.py", line 41, in wrapper
    rv = function(obj, *args, **kwargs)
  File "/usr/lib/python3.4/site-packages/jedi/api/__init__.py", line 309, in _get_under_cursor_stmt
    user_stmt = self._parser.user_stmt()
  File "/usr/lib/python3.4/site-packages/jedi/cache.py", line 143, in wrapper
    result = func(self)
  File "/usr/lib/python3.4/site-packages/jedi/parser/user_context.py", line 293, in user_stmt
    module = self.module()
  File "/usr/lib/python3.4/site-packages/jedi/parser/user_context.py", line 339, in module
    return self._parser().module
  File "/usr/lib/python3.4/site-packages/jedi/cache.py", line 143, in wrapper
    result = func(self)
  File "/usr/lib/python3.4/site-packages/jedi/parser/user_context.py", line 283, in _parser
    parser = FastParser(self._grammar, self._source, self._path)
  File "/usr/lib/python3.4/site-packages/jedi/parser/fast.py", line 109, in __call__
    p.update(source)
  File "/usr/lib/python3.4/site-packages/jedi/parser/fast.py", line 257, in update
    self._parse(source)
  File "/usr/lib/python3.4/site-packages/jedi/parser/fast.py", line 383, in _parse
    line_offset, nodes)
  File "/usr/lib/python3.4/site-packages/jedi/parser/fast.py", line 435, in _get_node
    p = Parser(self._grammar, parser_code, self.module_path, tokenizer=tokenizer)
  File "/usr/lib/python3.4/site-packages/jedi/parser/__init__.py", line 155, in __init__
    self.module = p.parse(self._tokenize(tokenizer))
  File "/usr/lib/python3.4/site-packages/jedi/parser/pgen2/parse.py", line 114, in parse
    raise ParseError("incomplete input", type, value, start_pos)
jedi.parser.pgen2.parse.ParseError: incomplete input: type='ENDMARKER', value='', start_pos=(37, 0)

Jedi Debug Information

Jedi did not emit any debug info.

Reproduction:

import jedi

source = '''\
import sys
import time

# path append for development only
# sys.path.append('/home/pmatos/Projects/SoCo')
import soco
import ivona_api

import collections
import http.server
import http.client
import cgi
import urllib

IVONA_ACCESS=''
IVONA_SECRET=''

HOST_NAME = ''
PORT_NUMBER = 35353

MP3_URL = 'https://s3.eu-central-1.amazonaws.com/sounds/bell.mp3'
HELLO_URI = 'x-sonos-spotify:spotify%3atrack%3a6HMvJcdw6qLsyV1b5x29sa?sid=9&flags=8224&sn=1'

def save_system_state():
    """Saves system state into a Sonos State variable."""
    # Need to save:
    # * groups
    # * for each speaker:
    # ** volumes
    # ** if currently playing music, where is it playing?
    return None

def restore_system_state(state):
    return

def find_spk(name):
    """Returns the speaker with a given name or None."""
    speakers = soco.discover()
    for spk in speakers:
        if spk.player_name == name:
            return spk
    return None

def play_morningchime():
    """Plays morning chime to dining room speaker."""
    morningspk = find_spk('Office')

    # Available on 05.08.2016
    #  fr-FR: Celine, Mathieu
    # pt-BR: Vitoria, Ricardo
    # sv-SE: Astrid
    # en-GB: Amy, Brian, Emma
    # cy-GB: Gwyneth, Geraint
    # en-AU: Nicole, Russell
    # da-DK: Naja, Mads
    # it-IT: Carla, Giorgio
    # es-US: Penelope, Miguel
    # pt-PT: Cristiano, Ines
    # de-DE: Marlene, Hans
    # nl-NL: Lotte, Ruben
    # en-IN: Raveena
    # en-GB-WLS: Gwyneth, Geraint
    # nb-NO: Liv
    # en-US: Salli, Joey, Chipmunk, Eric, Idra, Kimberly
    # is-IS: Dora, Karl
    # ro-RO: Carmen
    # fr-CA: Chantal
    # ru-RU: Maxim, Tatyana
    # tr-TR: Filiz
    # es-ES: Conchita, Enrique
    # pl-PL: Agnieszka, Jacek, Ewa, Jan, Ma
    voicename = 'Salli'
    ivona = ivona_api.IvonaAPI(IVONA_ACCESS,
                               IVONA_SECRET,
                               voicename)
    ivona.text_to_speech('Good morning, what a beautiful it is. Rise and shine!;

def play_hello():
    """Plays the 'Hello, is it me you're looking for' by Lionel Ritchie
    from Spotify"""
    state = save_system_state()

    # unjoin so we can grab the office speaker
    office = find_spk('Office')
    if office is None:
        print("Can't find office")
        return

    # set volume
    office.unjoin()
    office.volume = 40
    office.play_uri(HELLO_URI, start=False)
    office.seek('00:00:42')
    office.play()
    time.sleep(9)
    office.stop()

    restore_system_state(state)

def play_bell():
    """This function plays a bell in partymode but restore the
    state of the system afterwards."""

    speakers = soco.discover()

    if speakers is None:
        print("Can't find speakers")
        exit()

    state = save_system_state()

    # unjoin so we can go to party mode
    for spk in speakers:
        spk.unjoin()

    # select one for master, doesn't matter which
    master = speakers.pop()
    master.partymode()

    # set volume
    master.volume = 40
    for spk in speakers:
        spk.volume = 40
    master.play_uri(MP3_URL)

    restore_system_state(state)

def decode_byte_dicts(data):
    if isinstance(data, bytes):
        return data.decode('utf-8')
    elif isinstance(data, collections.Mapping):
        return dict(map(decode_byte_dicts, data.items()))
    elif isinstance(data, collections.Iterable):
        return type(data)(map(decode_byte_dicts, data))
    else:
        return data

class MSHandler(http.server.BaseHTTPRequestHandler):
    def do_POST(self):
        self.send_response(200)
        print('headers are {}'.format(self.headers))
        ctype, pdict = cgi.parse_header(self.headers.get_content_type())
        print('ctype is {}'.format(ctype))
        print('params are {}'.format(pdict))
        if ctype == 'multipart/form-data':
            postvars = cgi.parse_multipart(self.rfile, pdict)
        elif (ctype == 'application/x-www-form-urlencoded'
              or ctype == 'text/plain'):
            length = int(self.headers['Content-Length'])
            print('content length is {}'.format(length))
            postvars = urllib.parse.parse_qs(self.rfile.read(length),
                                             keep_blank_values=1)
        else:
            postvars = {}

        vars = decode_byte_dicts(postvars)
        print('vars are {}'.format(vars))
        if vars['type'] == ['bell']:
            play_bell()

if __name__ == '__main__':
    server_class = http.server.HTTPServer
    httpd = server_class((HOST_NAME, PORT_NUMBER), MSHandler)
    print(time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER))
    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        pass
    httpd.server_close()
    print(time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER))
'''

script = jedi.Script(column=80, line=79, encoding='utf-8', source=source, path='/home/pmatos/Projects/ms-notifier/notifier.py')
script.call_signatures()
jorgenschaefer commented 8 years ago

Thank you for the report! This is a bug in Jedi – I forwarded the report upstream. :-)