Skip to content

Commit

Permalink
Fix _ComprehensionVisitor.get_pyobject()
Browse files Browse the repository at this point in the history
This should return AssignedName rather than DefinedName/PyDefinedObject.

Fix this error when analyzing module containing comprehensions:

    TypeError: 'PyDefinedObject' object is not subscriptable
  • Loading branch information
lieryan committed Oct 18, 2021
1 parent 9b659d0 commit 8e61f3f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions rope/base/pyobjectsdef.py
Expand Up @@ -579,10 +579,12 @@ def _comprehension(self, node):

def _Name(self, node):
if isinstance(node.ctx, ast.Store):
self.names[node.id] = DefinedName(self._get_pyobject(node))
self.names[node.id] = self._get_pyobject(node)

def _get_pyobject(self, node):
return pyobjects.PyDefinedObject(None, node, self.owner_object)
return pynames.AssignedName(
lineno=node.lineno, module=self.get_module()
)


class _GlobalVisitor(_ScopeVisitor):
Expand Down
9 changes: 9 additions & 0 deletions ropetest/advanced_oi_test.py
Expand Up @@ -1124,3 +1124,12 @@ def f(p):
a_class = pymod["A"].get_object()
x_var = pymod["x"].get_object().get_type()
self.assertEqual(a_class, x_var)

def test_set_comprehension(self):
code = dedent("""\
x = {s.strip() for s in X()}
x.add('x')
""")
self.mod.write(code)
pymod = self.project.get_pymodule(self.mod)
x_var = pymod['x'].pyobject.get()

0 comments on commit 8e61f3f

Please sign in to comment.