1. zjes
  2. rope_py3k
Issue #2 resolved

'With' object has no attribute 'optional_vars' in get_calltip

Jorgen Schäfer
created an issue

Hello! One of my users reported an issue with rope3k's get_calltip function when used inside a with block.

The following statement causes the issue when get_calltip is called from within the scope of the with statement:

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

The full backtrace:

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'

elpy ticket for reference: https://github.com/jorgenschaefer/elpy/issues/75

Comments (3)

  1. Log in to comment