summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhippo91 <guillaume.peillex@gmail.com>2021-02-06 12:21:24 +0100
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-02-10 19:30:13 +0100
commit28221cc28d45c19cf33905396ee5521a77f8a788 (patch)
tree5267dd46f252dabcf2a26db712ce8d67dc97b940
parent4944abaa7a1db6f3e59b9b5aaa58aef8e42eb55d (diff)
downloadastroid-git-28221cc28d45c19cf33905396ee5521a77f8a788.tar.gz
Adds the attr_fset property
-rw-r--r--astroid/interpreter/objectmodel.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/astroid/interpreter/objectmodel.py b/astroid/interpreter/objectmodel.py
index ae48ac11..3b0bfe13 100644
--- a/astroid/interpreter/objectmodel.py
+++ b/astroid/interpreter/objectmodel.py
@@ -795,6 +795,28 @@ class PropertyModel(ObjectModel):
return property_accessor
@property
+ def attr_fset(self):
+ from astroid.scoped_nodes import FunctionDef
+
+ func = self._instance
+
+ class PropertyFuncAccessor(FunctionDef):
+ def infer_call_result(self, caller=None, context=None):
+ nonlocal func
+ if caller and len(caller.args) != 2:
+ raise exceptions.InferenceError(
+ "fset() needs two arguments", target=self, context=context
+ )
+
+ yield from func.function.infer_call_result(
+ caller=caller, context=context
+ )
+
+ property_accessor = PropertyFuncAccessor(name="fset", parent=self._instance)
+ property_accessor.postinit(args=func.args, body=func.body)
+ return property_accessor
+
+ @property
def attr_setter(self):
return self._init_function("setter")