summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhippo91 <guillaume.peillex@gmail.com>2021-02-07 16:21:09 +0100
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-02-10 19:30:13 +0100
commit3c6a22e25cb0e087cfe8e7b0c02f199b18f6675b (patch)
tree7054c389cd5bfb80783718594f472a323e57e0c7
parent7179392e2b70c97109fced64eae72c1ee7cda87b (diff)
downloadastroid-git-3c6a22e25cb0e087cfe8e7b0c02f199b18f6675b.tar.gz
Adds docstring and reformat attr_fset method
-rw-r--r--astroid/interpreter/objectmodel.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/astroid/interpreter/objectmodel.py b/astroid/interpreter/objectmodel.py
index f1c25baf..f85d5cb2 100644
--- a/astroid/interpreter/objectmodel.py
+++ b/astroid/interpreter/objectmodel.py
@@ -806,26 +806,30 @@ class PropertyModel(ObjectModel):
func = self._instance
def find_setter(func: objects.Property) -> Optional[astroid.FunctionDef]:
- for target in func.parent.get_children():
- if target.name == func.function.name:
- for dec_name in target.decoratornames():
- if dec_name.endswith(func.function.name + ".setter"):
- return target
+ """
+ Given a property, find the corresponding setter function and returns it.
+
+ :param func: property for which the setter has to be found
+ :return: the setter function or None
+ """
+ for target in [t for t in func.parent.get_children() if t.name == func.function.name]:
+ for dec_name in target.decoratornames():
+ if dec_name.endswith(func.function.name + ".setter"):
+ return target
return None
func_setter = find_setter(func)
+ if not func_setter:
+ raise exceptions.InferenceError(
+ f"Unable to find the setter of property {func.function.name}")
+
class PropertyFuncAccessor(FunctionDef):
def infer_call_result(self, caller=None, context=None):
- nonlocal func
+ nonlocal func_setter
if caller and len(caller.args) != 2:
raise exceptions.InferenceError(
"fset() needs two arguments", target=self, context=context
)
-
- func_setter = find_setter(func)
- if not func_setter:
- raise exceptions.InferenceError(
- f"Unable to find the setter of property {func.function.name}")
yield from func_setter.infer_call_result(
caller=caller, context=context
)