summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2020-03-26 09:26:00 +0100
committerClaudiu Popa <pcmanticore@gmail.com>2020-03-26 09:26:00 +0100
commit76fd7aa73cfbe650c97bf6828adb7e39490c3e99 (patch)
tree54f1e9bfafce7efa1fe1d2e84c18f4f33ee998d8 /tests
parentab9d147d71c3dff39972b7d2173aa66a616ff5b7 (diff)
downloadastroid-git-76fd7aa73cfbe650c97bf6828adb7e39490c3e99.tar.gz
Allow `FunctionDef.getattr` to look into both instance attrs and special attributes
Modifying an attribute of a function with an augmented assignment resulted in `FunctionDef.getattr` to prioritize the instance attributes fetching. This means that only the augmented assignment modification would have been visible. Close PyCQA/pylint#1078
Diffstat (limited to 'tests')
-rw-r--r--tests/unittest_inference.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/unittest_inference.py b/tests/unittest_inference.py
index 7fc5990a..b2210a8d 100644
--- a/tests/unittest_inference.py
+++ b/tests/unittest_inference.py
@@ -5775,5 +5775,21 @@ def test_recursion_error_self_reference_type_call():
assert [cls.name for cls in inferred.mro()] == ["B", "A", "object"]
+def test_allow_retrieving_instance_attrs_and_special_attrs_for_functions():
+ code = """
+ class A:
+ def test(self):
+ "a"
+ # Add `__doc__` to `FunctionDef.instance_attrs` via an `AugAssign`
+ test.__doc__ += 'b'
+ test #@
+ """
+ node = extract_node(code)
+ inferred = next(node.infer())
+ attrs = inferred.getattr("__doc__")
+ # One from the `AugAssign`, one from the special attributes
+ assert len(attrs) == 2
+
+
if __name__ == "__main__":
unittest.main()