summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2020-12-30 10:58:17 +0100
committerClaudiu Popa <pcmanticore@gmail.com>2020-12-30 10:58:17 +0100
commita0d7601b6205a0c6167fdd73fc121e2acfb09856 (patch)
tree1e93111d2ba29a7389a692910937ae6562e7462f
parent99d9c77cc276b1c5f5d76d91282d05b5df3a2c21 (diff)
downloadastroid-git-fix-crash-in-dunder-inference.tar.gz
Fix a bug for dunder methods inference of function objectsfix-crash-in-dunder-inference
Fixes #819
-rw-r--r--ChangeLog4
-rw-r--r--astroid/interpreter/objectmodel.py1
-rw-r--r--tests/unittest_regrtest.py11
3 files changed, 16 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 560544be..144afdf8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -15,6 +15,10 @@ Release Date: TBA
Fixes PyCQA/pylint#3640
+* Fix a bug for dunder methods inference of function objects
+
+ Fixes #819
+
* Fixes a bug in the signature of the ``ndarray.__or__`` method,
in the ``brain_numpy_ndarray.py`` module.
diff --git a/astroid/interpreter/objectmodel.py b/astroid/interpreter/objectmodel.py
index 3eca5722..ae48ac11 100644
--- a/astroid/interpreter/objectmodel.py
+++ b/astroid/interpreter/objectmodel.py
@@ -324,6 +324,7 @@ class FunctionModel(ObjectModel):
doc=func.doc,
lineno=func.lineno,
col_offset=func.col_offset,
+ parent=func.parent,
)
# pylint: disable=no-member
new_func.postinit(func.args, func.body, func.decorators, func.returns)
diff --git a/tests/unittest_regrtest.py b/tests/unittest_regrtest.py
index 17668edd..b75e3dfe 100644
--- a/tests/unittest_regrtest.py
+++ b/tests/unittest_regrtest.py
@@ -343,5 +343,16 @@ def test_ancestor_looking_up_redefined_function():
assert isinstance(found[0], nodes.FunctionDef)
+def test_crash_in_dunder_inference_prevented():
+ code = """
+ class MyClass():
+ def fu(self, objects):
+ delitem = dict.__delitem__.__get__(self, dict)
+ delitem #@
+ """
+ inferred = next(extract_node(code).infer())
+ assert "builtins.dict.__delitem__" == inferred.qname()
+
+
if __name__ == "__main__":
unittest.main()