eldoc error: (error 'With' object has no attribute 'optional_vars') #75

Closed
benalexau opened this Issue May 10, 2013 · 6 comments

Comments

Projects
None yet
2 participants

When editing a source file which contains a with statement, positioning the cursor anywhere within the with block will produce an error message in the minibuffer and *Messages* buffer: eldoc error: (error 'With' object has no attribute 'optional_vars').

To reproduce, use the same environment (versions and project structure) as reported in #74 and modify test_calculator.py to show an additional method containing a with statement:

    def test_with_statement(self):
        with open('output.txt', 'w') as f:
            f.write('Hi there!')

Positioning the cursor within the with block will show the error.

Owner

jorgenschaefer commented May 10, 2013

You're a great tester. :-D I don't seem to be able to reproduce this, could you run M-: (elpy-rpc "get_traceback") after getting that error and copy the backtrace that emits to the *Messages* buffer here?

No worries. Happy to help making elpy better -- it's great!

Here's the traceback:

"Traceback (most recent call last):
  File \"/home/balex/.virtualenvs/testing/lib/python3.3/site-packages/elpy/rpc.py\", line 103, in handle_request
    result = self.handle(method_name, params)
  File \"/home/balex/.virtualenvs/testing/lib/python3.3/site-packages/elpy/server.py\", line 50, in handle
    return method(*args)
  File \"/home/balex/.virtualenvs/testing/lib/python3.3/site-packages/elpy/backends/ropebackend.py\", line 160, in rpc_get_calltip
    remove_self=True)
  File \"/home/balex/.virtualenvs/testing/lib/python3.3/site-packages/rope/contrib/codeassist.py\", line 94, in get_calltip
    pyname = fixer.pyname_at(offset)
  File \"/home/balex/.virtualenvs/testing/lib/python3.3/site-packages/rope/contrib/fixsyntax.py\", line 63, in pyname_at
    return new_pyname()
  File \"/home/balex/.virtualenvs/testing/lib/python3.3/site-packages/rope/contrib/fixsyntax.py\", line 61, in new_pyname
    return rope.base.evaluate.eval_location(pymodule, newoffset)
  File \"/home/balex/.virtualenvs/testing/lib/python3.3/site-packages/rope/base/evaluate.py\", line 11, in eval_location
    return eval_location2(pymodule, offset)[1]
  File \"/home/balex/.virtualenvs/testing/lib/python3.3/site-packages/rope/base/evaluate.py\", line 17, in eval_location2
    return pyname_finder.get_primary_and_pyname_at(offset)
  File \"/home/balex/.virtualenvs/testing/lib/python3.3/site-packages/rope/base/evaluate.py\", line 78, in get_primary_and_pyname_at
    holding_scope = self.module_scope.get_inner_scope_for_line(lineno)
  File \"/home/balex/.virtualenvs/testing/lib/python3.3/site-packages/rope/base/pyscopes.py\", line 132, in get_inner_scope_for_line
    return self._scope_finder.get_holding_scope(self, lineno, indents)
  File \"/home/balex/.virtualenvs/testing/lib/python3.3/site-packages/rope/base/pyscopes.py\", line 240, in get_holding_scope
    for scope in current_scope.get_scopes():
  File \"/home/balex/.virtualenvs/testing/lib/python3.3/site-packages/rope/base/utils.py\", line 10, in _wrapper
    setattr(self, name, func(self, *args, **kwds))
  File \"/home/balex/.virtualenvs/testing/lib/python3.3/site-packages/rope/base/pyscopes.py\", line 42, in get_scopes
    return self._create_scopes()
  File \"/home/balex/.virtualenvs/testing/lib/python3.3/site-packages/rope/base/pyscopes.py\", line 189, in _create_scopes
    self._visit_function()
  File \"/home/balex/.virtualenvs/testing/lib/python3.3/site-packages/rope/base/pyscopes.py\", line 167, in _visit_function
    ast.walk(n, new_visitor)
  File \"/home/balex/.virtualenvs/testing/lib/python3.3/site-packages/rope/base/ast.py\", line 31, in walk
    return method(node)
  File \"/home/balex/.virtualenvs/testing/lib/python3.3/site-packages/rope/base/pyobjectsdef.py\", line 380, in _With
    if node.optional_vars:
AttributeError: 'With' object has no attribute 'optional_vars'
"
Owner

jorgenschaefer commented May 10, 2013

Ok, that's a bug in rope_3k. I'll forward that upstream. Thanks again!

Jorgen, would you mind posting a link to the upstream report when made, so I can watch it there? I also found Jedi had problems with M-. jumping to methods defined in the same module (eg self.foo()), plus C-c C-d would report no documentation available. Both of those use cases work fine with Rope. The only Rope issue I've found is this AttributeError: 'With' object has no attribute 'optional_vars' misbehaviour when a with block is encountered, although fortunately the inconvenience is minimal given you can relocate the code in the block to a separate function.

Owner

jorgenschaefer commented May 31, 2013

According to upstream, this will be fixed in the next release of rope_py3k.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment