From 549e17679dd3cf5f23d4c2636e6b987654238dd5 Mon Sep 17 00:00:00 2001 From: areveny Date: Thu, 20 Jan 2022 13:25:22 -0600 Subject: Fix builtin inference on property not including function arguments --- ChangeLog | 2 ++ astroid/brain/brain_builtin_inference.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 3bb23e2d..1e3155b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,8 @@ What's New in astroid 2.10.0? ============================= Release date: TBA +* Fixed builtin inferenence on `property` calls not calling the `postinit` of the new node, which + resulted in instance arguments missing on these nodes. What's New in astroid 2.9.4? ============================ diff --git a/astroid/brain/brain_builtin_inference.py b/astroid/brain/brain_builtin_inference.py index 0bf35260..f5114617 100644 --- a/astroid/brain/brain_builtin_inference.py +++ b/astroid/brain/brain_builtin_inference.py @@ -566,7 +566,7 @@ def infer_property(node, context=None): if not isinstance(inferred, (nodes.FunctionDef, nodes.Lambda)): raise UseInferenceDefault - return objects.Property( + prop_func = objects.Property( function=inferred, name=inferred.name, doc=getattr(inferred, "doc", None), @@ -574,6 +574,8 @@ def infer_property(node, context=None): parent=node, col_offset=node.col_offset, ) + prop_func.postinit(body=[], args=inferred.args) + return prop_func def infer_bool(node, context=None): -- cgit v1.2.1 From cb33cb7e1947ba745801b4255acdca35c869ff65 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 20 Jan 2022 20:30:30 +0000 Subject: [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 1e3155b1..89bcdb5f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,7 +6,7 @@ What's New in astroid 2.10.0? ============================= Release date: TBA -* Fixed builtin inferenence on `property` calls not calling the `postinit` of the new node, which +* Fixed builtin inferenence on `property` calls not calling the `postinit` of the new node, which resulted in instance arguments missing on these nodes. What's New in astroid 2.9.4? -- cgit v1.2.1 From 9e7898253e57544acaea53a77d728dcebf092e74 Mon Sep 17 00:00:00 2001 From: areveny Date: Thu, 20 Jan 2022 17:10:48 -0600 Subject: Add unittest for property inference postinit --- tests/unittest_brain_builtin.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/unittest_brain_builtin.py diff --git a/tests/unittest_brain_builtin.py b/tests/unittest_brain_builtin.py new file mode 100644 index 00000000..f0e4b525 --- /dev/null +++ b/tests/unittest_brain_builtin.py @@ -0,0 +1,21 @@ +# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html +# For details: https://github.com/PyCQA/astroid/blob/main/LICENSE +"""Unit Tests for the builtins brain module.""" + +import unittest + +from astroid import extract_node, objects + +class BuiltinsTest(unittest.TestCase): + def test_infer_property(self): + class_with_property = extract_node( + """ + class Something: + def getter(): + return 5 + asd = property(getter) #@ + """ + ) + inferred_property = list(class_with_property.value.infer())[0] + assert isinstance(inferred_property, objects.Property) + assert hasattr(inferred_property, "args") -- cgit v1.2.1 From 3db9745970ae64c4f92788afb9c4b212b53f79e9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 20 Jan 2022 23:11:41 +0000 Subject: [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/unittest_brain_builtin.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/unittest_brain_builtin.py b/tests/unittest_brain_builtin.py index f0e4b525..e45b80f7 100644 --- a/tests/unittest_brain_builtin.py +++ b/tests/unittest_brain_builtin.py @@ -6,10 +6,11 @@ import unittest from astroid import extract_node, objects + class BuiltinsTest(unittest.TestCase): def test_infer_property(self): class_with_property = extract_node( - """ + """ class Something: def getter(): return 5 @@ -17,5 +18,5 @@ class BuiltinsTest(unittest.TestCase): """ ) inferred_property = list(class_with_property.value.infer())[0] - assert isinstance(inferred_property, objects.Property) - assert hasattr(inferred_property, "args") + self.assertTrue(isinstance(inferred_property, objects.Property)) + self.assertTrue(hasattr(inferred_property, "args")) -- cgit v1.2.1