1
0
forked from VimPlug/jedi

Move is_side_effect to Definition and correct bugs

This commit is contained in:
Dave Halter
2020-02-04 20:12:24 +01:00
parent 6313934d94
commit 670d6e8639
2 changed files with 17 additions and 14 deletions

View File

@@ -523,16 +523,6 @@ class BaseDefinition(object):
""" """
return self._name.infer().get_type_hint() 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): class Completion(BaseDefinition):
""" """
@@ -717,6 +707,16 @@ class Definition(BaseDefinition):
else: else:
return self._name.tree_name.is_definition() 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): def __eq__(self, other):
return self._name.start_pos == other._name.start_pos \ return self._name.start_pos == other._name.start_pos \
and self.module_path == other.module_path \ and self.module_path == other.module_path \

View File

@@ -175,12 +175,15 @@ def test_no_error(get_names):
'code, index, is_side_effect', [ 'code, index, is_side_effect', [
('x', 0, False), ('x', 0, False),
('x.x', 0, False), ('x.x', 0, False),
('x.x', 1, True), ('x.x', 1, False),
('def x(x): x.x', 1, False), ('x.x = 3', 0, False),
('def x(x): x.x', 3, True), ('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', 0, False),
('import sys; sys.path', 1, 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): def test_is_side_effect(get_names, code, index, is_side_effect):