forked from VimPlug/jedi
Move is_side_effect to Definition and correct bugs
This commit is contained in:
@@ -523,16 +523,6 @@ class BaseDefinition(object):
|
||||
"""
|
||||
return self._name.infer().get_type_hint()
|
||||
|
||||
def is_side_effect(self):
|
||||
"""
|
||||
Checks if a name is defined as ``self.foo = 3``. In case of self, this
|
||||
function would return False, for foo it would return True.
|
||||
"""
|
||||
tree_name = self._name.tree_name
|
||||
if tree_name is None:
|
||||
return False
|
||||
return tree_name.parent.type == 'trailer'
|
||||
|
||||
|
||||
class Completion(BaseDefinition):
|
||||
"""
|
||||
@@ -717,6 +707,16 @@ class Definition(BaseDefinition):
|
||||
else:
|
||||
return self._name.tree_name.is_definition()
|
||||
|
||||
def is_side_effect(self):
|
||||
"""
|
||||
Checks if a name is defined as ``self.foo = 3``. In case of self, this
|
||||
function would return False, for foo it would return True.
|
||||
"""
|
||||
tree_name = self._name.tree_name
|
||||
if tree_name is None:
|
||||
return False
|
||||
return tree_name.is_definition() and tree_name.parent.type == 'trailer'
|
||||
|
||||
def __eq__(self, other):
|
||||
return self._name.start_pos == other._name.start_pos \
|
||||
and self.module_path == other.module_path \
|
||||
|
||||
@@ -175,12 +175,15 @@ def test_no_error(get_names):
|
||||
'code, index, is_side_effect', [
|
||||
('x', 0, False),
|
||||
('x.x', 0, False),
|
||||
('x.x', 1, True),
|
||||
('def x(x): x.x', 1, False),
|
||||
('def x(x): x.x', 3, True),
|
||||
('x.x', 1, False),
|
||||
('x.x = 3', 0, False),
|
||||
('x.x = 3', 1, True),
|
||||
('def x(x): x.x = 3', 1, False),
|
||||
('def x(x): x.x = 3', 3, True),
|
||||
('import sys; sys.path', 0, False),
|
||||
('import sys; sys.path', 1, False),
|
||||
('import sys; sys.path', 2, True),
|
||||
('import sys; sys.path', 2, False),
|
||||
('import sys; sys.path = []', 2, True),
|
||||
]
|
||||
)
|
||||
def test_is_side_effect(get_names, code, index, is_side_effect):
|
||||
|
||||
Reference in New Issue
Block a user