diff options
| author | Arianna <self@areveny.com> | 2022-01-20 18:16:17 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-20 18:16:17 -0600 |
| commit | 3047277175e229a938a4dd83b0cde1015f473020 (patch) | |
| tree | 1ed6e70b716b990988fc88fa323b37b2cb02b776 | |
| parent | e00545978158ced5bacf8fede365efd0d690d320 (diff) | |
| parent | 3db9745970ae64c4f92788afb9c4b212b53f79e9 (diff) | |
| download | astroid-git-3047277175e229a938a4dd83b0cde1015f473020.tar.gz | |
Fix builtin inference on property not including function arguments
| -rw-r--r-- | ChangeLog | 2 | ||||
| -rw-r--r-- | astroid/brain/brain_builtin_inference.py | 4 | ||||
| -rw-r--r-- | tests/unittest_brain_builtin.py | 22 |
3 files changed, 27 insertions, 1 deletions
@@ -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): diff --git a/tests/unittest_brain_builtin.py b/tests/unittest_brain_builtin.py new file mode 100644 index 00000000..e45b80f7 --- /dev/null +++ b/tests/unittest_brain_builtin.py @@ -0,0 +1,22 @@ +# 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] + self.assertTrue(isinstance(inferred_property, objects.Property)) + self.assertTrue(hasattr(inferred_property, "args")) |
