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

This commit is contained in:
eirannejad
2024-02-07 14:19:36 -06:00
parent 740b474eda
commit 49ae9b4291

View File

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