diff options
| author | Claudiu Popa <pcmanticore@gmail.com> | 2020-12-30 10:58:17 +0100 |
|---|---|---|
| committer | Claudiu Popa <pcmanticore@gmail.com> | 2020-12-30 11:47:27 +0100 |
| commit | 00ccda69584785fd22025a3f821e1c3437302eaa (patch) | |
| tree | 95ba9abf3a4b4361a99a6a8a9fa12d1cae28d91e | |
| parent | 98fd2173be45a04df49735862b994e1c6c7028d2 (diff) | |
| download | astroid-git-00ccda69584785fd22025a3f821e1c3437302eaa.tar.gz | |
Fix a bug for dunder methods inference of function objects
Fixes #819
| -rw-r--r-- | ChangeLog | 4 | ||||
| -rw-r--r-- | astroid/interpreter/objectmodel.py | 1 | ||||
| -rw-r--r-- | tests/unittest_regrtest.py | 11 |
3 files changed, 16 insertions, 0 deletions
@@ -22,6 +22,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() |
