summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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()