properties with setters are now reported as 'property' for completion (#1983)

* properties with setters are now reported as 'property' for completion

* code cleanups

* fixed test

* fixed tests

* Revert "fixed test"

This reverts commit a80c955a48.

* code quality cleanup

* so picky

* Revert "Revert "fixed test""

This reverts commit 58dfc5292e.

* updated test per maintainer comments #1983

* removed extra char
This commit is contained in:
Ehsan Iran-Nejad
2024-02-19 06:07:47 -06:00
committed by GitHub
parent 740b474eda
commit 54a6dadde3
3 changed files with 13 additions and 11 deletions

View File

@@ -320,7 +320,7 @@ def expr_is_dotted(node):
return node.type == 'name' return node.type == 'name'
def _function_is_x_method(*method_names): def _function_is_x_method(decorator_checker):
def wrapper(function_node): def wrapper(function_node):
""" """
This is a heuristic. It will not hold ALL the times, but it will be This is a heuristic. It will not hold ALL the times, but it will be
@@ -330,12 +330,16 @@ def _function_is_x_method(*method_names):
""" """
for decorator in function_node.get_decorators(): for decorator in function_node.get_decorators():
dotted_name = decorator.children[1] dotted_name = decorator.children[1]
if dotted_name.get_code() in method_names: if decorator_checker(dotted_name.get_code()):
return True return True
return False return False
return wrapper return wrapper
function_is_staticmethod = _function_is_x_method('staticmethod') function_is_staticmethod = _function_is_x_method(lambda m: m == "staticmethod")
function_is_classmethod = _function_is_x_method('classmethod') function_is_classmethod = _function_is_x_method(lambda m: m == "classmethod")
function_is_property = _function_is_x_method('property', 'cached_property') function_is_property = _function_is_x_method(
lambda m: m == "property"
or m == "cached_property"
or (m.endswith(".setter"))
)

View File

@@ -21,11 +21,9 @@ class Y(X):
#? [] #? []
def __doc__ def __doc__
# This might or might not be what we wanted, currently properties are also
# used like this. IMO this is not wanted ~dave.
#? ['__class__']
def __class__
#? [] #? []
def __class__
#? ['__class__']
__class__ __class__

View File

@@ -348,8 +348,8 @@ def test_parent_on_comprehension(Script):
def test_type(Script): def test_type(Script):
for c in Script('a = [str()]; a[0].').complete(): for c in Script('a = [str()]; a[0].').complete():
if c.name == '__class__' and False: # TODO fix. if c.name == '__class__':
assert c.type == 'class' assert c.type == 'property'
else: else:
assert c.type in ('function', 'statement') assert c.type in ('function', 'statement')