diff options
author | Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> | 2023-04-23 11:33:29 +0200 |
---|---|---|
committer | Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> | 2023-04-23 12:01:50 +0200 |
commit | 30df5a84bf8d9ed14e90defb8dc3359b9e25f7e5 (patch) | |
tree | 205275f953fdc65ea7e2c63065f54398d7060f67 /astroid | |
parent | de0751c5c4cb0918880752fe5c0a1ce26fb2ec61 (diff) | |
download | astroid-git-30df5a84bf8d9ed14e90defb8dc3359b9e25f7e5.tar.gz |
Fix constructors of ``Super``
Diffstat (limited to 'astroid')
-rw-r--r-- | astroid/brain/brain_builtin_inference.py | 11 | ||||
-rw-r--r-- | astroid/objects.py | 31 |
2 files changed, 29 insertions, 13 deletions
diff --git a/astroid/brain/brain_builtin_inference.py b/astroid/brain/brain_builtin_inference.py index 097404af..af1f9f9a 100644 --- a/astroid/brain/brain_builtin_inference.py +++ b/astroid/brain/brain_builtin_inference.py @@ -379,7 +379,9 @@ def infer_dict(node, context: InferenceContext | None = None): return value -def infer_super(node, context: InferenceContext | None = None): +def infer_super( + node: nodes.Call, context: InferenceContext | None = None +) -> objects.Super: """Understand super calls. There are some restrictions for what can be understood: @@ -405,6 +407,7 @@ def infer_super(node, context: InferenceContext | None = None): raise UseInferenceDefault cls = scoped_nodes.get_wrapping_class(scope) + assert cls is not None if not node.args: mro_pointer = cls # In we are in a classmethod, the interpreter will fill @@ -430,7 +433,11 @@ def infer_super(node, context: InferenceContext | None = None): raise UseInferenceDefault super_obj = objects.Super( - mro_pointer=mro_pointer, mro_type=mro_type, self_class=cls, scope=scope + mro_pointer=mro_pointer, + mro_type=mro_type, + self_class=cls, + scope=scope, + call=node, ) super_obj.parent = node return super_obj diff --git a/astroid/objects.py b/astroid/objects.py index 32fda287..08750b3e 100644 --- a/astroid/objects.py +++ b/astroid/objects.py @@ -25,11 +25,10 @@ from astroid.exceptions import ( MroError, SuperError, ) +from astroid.interpreter import objectmodel from astroid.manager import AstroidManager from astroid.nodes import node_classes, scoped_nodes -from astroid.typing import InferenceResult - -objectmodel = util.lazy_import("interpreter.objectmodel") +from astroid.typing import InferenceResult, SuccessfulInferenceResult if sys.version_info >= (3, 8): from functools import cached_property @@ -70,16 +69,28 @@ class Super(node_classes.NodeNG): *scope* is the function where the super call is. """ - # pylint: disable=unnecessary-lambda - special_attributes = util.lazy_descriptor(lambda: objectmodel.SuperModel()) + special_attributes = objectmodel.SuperModel() - def __init__(self, mro_pointer, mro_type, self_class, scope): + def __init__( + self, + mro_pointer: SuccessfulInferenceResult, + mro_type: SuccessfulInferenceResult, + self_class: scoped_nodes.ClassDef, + scope: scoped_nodes.FunctionDef, + call: node_classes.Call, + ) -> None: self.type = mro_type self.mro_pointer = mro_pointer self._class_based = False self._self_class = self_class self._scope = scope - super().__init__() + super().__init__( + parent=scope, + lineno=scope.lineno, + col_offset=scope.col_offset, + end_lineno=scope.end_lineno, + end_col_offset=scope.end_col_offset, + ) def _infer(self, context: InferenceContext | None = None, **kwargs: Any): yield self @@ -249,8 +260,7 @@ class DictInstance(bases.Instance): that methods such as .values or .items can be properly inferred. """ - # pylint: disable=unnecessary-lambda - special_attributes = util.lazy_descriptor(lambda: objectmodel.DictModel()) + special_attributes = objectmodel.DictModel() # Custom objects tailored for dictionaries, which are used to @@ -348,8 +358,7 @@ class Property(scoped_nodes.FunctionDef): # Assigned directly to prevent triggering the DeprecationWarning. self._doc = doc - # pylint: disable=unnecessary-lambda - special_attributes = util.lazy_descriptor(lambda: objectmodel.PropertyModel()) + special_attributes = objectmodel.PropertyModel() type = "property" def pytype(self) -> Literal["builtins.property"]: |